?用戶信息
實現(xiàn)用戶頭像昵稱區(qū)域的基本布局
-
在?
my-userinfo
?組件中,定義如下的 UI 結構:
<template>
<view class="my-userinfo-container">
<!-- 頭像昵稱區(qū)域 -->
<view class="top-box">
<image src="" class="avatar"></image>
<view class="nickname">xxx</view>
</view>
</view>
</template>
美化當前組件的樣式:
.my-userinfo-container {
height: 100%;
// 為整個組件的結構添加淺灰色的背景
background-color: #f4f4f4;
.top-box {
height: 400rpx;
background-color: #c00000;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
.avatar {
display: block;
width: 90px;
height: 90px;
border-radius: 45px;
border: 2px solid white;
box-shadow: 0 1px 5px black;
}
.nickname {
color: white;
font-weight: bold;
font-size: 16px;
margin-top: 10px;
}
}
}
在?my.vue
?頁面中,為最外層包裹性質(zhì)的?view
?容器,添加?class="my-container"
?的類名,并美化樣式如下:
page,
.my-container {
height: 100%;
}
?
?
?文章來源地址http://www.zghlxwxcb.cn/news/detail-416779.html
渲染用戶的頭像和昵稱
-
在?
my-userinfo
?組件中,通過?mapState
?輔助函數(shù),將需要的成員映射到當前組件中使用:
// 按需導入 mapState 輔助函數(shù)
import { mapState } from 'vuex'
export default {
computed: {
// 將 m_user 模塊中的 userinfo 映射到當前頁面中使用
...mapState('m_user', ['userinfo']),
},
data() {
return {}
},
}
將用戶的頭像和昵稱渲染到頁面中:
<!-- 頭像昵稱區(qū)域 -->
<view class="top-box">
<image :src="userinfo.avatarUrl" class="avatar"></image>
<view class="nickname">{{userinfo.nickName}}</view>
</view>
?
?渲染第一個面板區(qū)域
在?my-userinfo
?組件中,定義如下的 UI 結構:
<!-- 面板的列表區(qū)域 -->
<view class="panel-list">
<!-- 第一個面板 -->
<view class="panel">
<!-- panel 的主體區(qū)域 -->
<view class="panel-body">
<!-- panel 的 item 項 -->
<view class="panel-item">
<text>8</text>
<text>收藏的店鋪</text>
</view>
<view class="panel-item">
<text>14</text>
<text>收藏的商品</text>
</view>
<view class="panel-item">
<text>18</text>
<text>關注的商品</text>
</view>
<view class="panel-item">
<text>84</text>
<text>足跡</text>
</view>
</view>
</view>
<!-- 第二個面板 -->
<!-- 第三個面板 -->
</view>
美化第一個面板的樣式:
.panel-list {
padding: 0 10px;
position: relative;
top: -10px;
.panel {
background-color: white;
border-radius: 3px;
margin-bottom: 8px;
.panel-body {
display: flex;
justify-content: space-around;
.panel-item {
display: flex;
flex-direction: column;
align-items: center;
justify-content: space-around;
font-size: 13px;
padding: 10px 0;
}
}
}
}
?
?
渲染第二個面板區(qū)域
-
定義第二個面板區(qū)域的 UI 結構:
<!-- 第二個面板 -->
<view class="panel">
<!-- 面板的標題 -->
<view class="panel-title">我的訂單</view>
<!-- 面板的主體 -->
<view class="panel-body">
<!-- 面板主體中的 item 項 -->
<view class="panel-item">
<image src="/static/my-icons/icon1.png" class="icon"></image>
<text>待付款</text>
</view>
<view class="panel-item">
<image src="/static/my-icons/icon2.png" class="icon"></image>
<text>待收貨</text>
</view>
<view class="panel-item">
<image src="/static/my-icons/icon3.png" class="icon"></image>
<text>退款/退貨</text>
</view>
<view class="panel-item">
<image src="/static/my-icons/icon4.png" class="icon"></image>
<text>全部訂單</text>
</view>
</view>
</view>
對之前的 SCSS 樣式進行改造,從而美化第二個面板的樣式:
.panel-list {
padding: 0 10px;
position: relative;
top: -10px;
.panel {
background-color: white;
border-radius: 3px;
margin-bottom: 8px;
.panel-title {
line-height: 45px;
padding-left: 10px;
font-size: 15px;
border-bottom: 1px solid #f4f4f4;
}
.panel-body {
display: flex;
justify-content: space-around;
.panel-item {
display: flex;
flex-direction: column;
align-items: center;
justify-content: space-around;
font-size: 13px;
padding: 10px 0;
.icon {
width: 35px;
height: 35px;
}
}
}
}
}
?
??
?渲染第三個面板區(qū)域
定義第三個面板區(qū)域的 UI 結構:
<!-- 第三個面板 -->
<view class="panel">
<view class="panel-list-item">
<text>收貨地址</text>
<uni-icons type="arrowright" size="15"></uni-icons>
</view>
<view class="panel-list-item">
<text>聯(lián)系客服</text>
<uni-icons type="arrowright" size="15"></uni-icons>
</view>
<view class="panel-list-item">
<text>退出登錄</text>
<uni-icons type="arrowright" size="15"></uni-icons>
</view>
</view>
美化第三個面板區(qū)域的樣式:
.panel-list-item {
height: 45px;
display: flex;
justify-content: space-between;
align-items: center;
font-size: 15px;
padding: 0 10px;
}
?
?實現(xiàn)退出登錄的功能
為第三個面板區(qū)域中的?退出登錄
?項綁定?click
?點擊事件處理函數(shù):
<view class="panel-list-item" @click="logout">
<text>退出登錄</text>
<uni-icons type="arrowright" size="15"></uni-icons>
</view>
在?my-userinfo
?組件的?methods
?節(jié)點中定義?logout
?事件處理函數(shù):
// 退出登錄
async logout() {
// 詢問用戶是否退出登錄
const [err, succ] = await uni.showModal({
title: '提示',
content: '確認退出登錄嗎?'
}).catch(err => err)
if (succ && succ.confirm) {
// 用戶確認了退出登錄的操作
// 需要清空 vuex 中的 userinfo、token 和 address
this.updateUserInfo({})
this.updateToken('')
this.updateAddress({})
}
}
使用?mapMutations
?輔助方法,將需要用到的 mutations 方法映射到當前組件中:
// 按需導入輔助函數(shù)
import { mapState, mapMutations } from 'vuex'
export default {
methods: {
...mapMutations('m_user', ['updateUserInfo', 'updateToken', 'updateAddress']),
},
}
?
?文章來源:http://www.zghlxwxcb.cn/news/detail-416779.html
?
到了這里,關于uni-app:登錄與支付--用戶信息的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!