当前位置:网站首页>微信小程序点击获取昵称头像
微信小程序点击获取昵称头像
2022-08-07 05:12:00 【张帆X】
1.写好html内容,v-if和v-else,如果有数据就显示头像昵称,反之显示button按钮
<view class="login" wx:if="{
{loginList.avatarUrl}}">
<image src="{
{loginList.avatarUrl}}"></image>
<text>{
{loginList.nickName}}</text>
</view>
<button bindtap="onclick" wx:else>获取头像昵称</button>2.写按钮事件,微信小程序自带的getUserProfile方法
desc必写,成功后打印并赋值
onclick(){
wx.getUserProfile({
desc: 'desc',
success:(res)=>{
console.log(res);
this.setData({
loginList:res.userInfo
})
}
})
}3.data中定义变量接收数据
/**
* 页面的初始数据
*/
data: {
loginList:{}
}4.当刷新时还在登录状态,除非点击退出登录
wx.getUserProfile({
desc: '获取用户信息',
success: (res) => {
// console.log(res);
this.setData({
userInfo: res.userInfo
})
wx.setStorage({
key: 'userInfo',
data: res.userInfo
})
}
})
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
wx.getStorage({
key: 'userInfo',
success: (res) => {
// console.log(res);
this.setData({
userInfo: res.data
})
}
})
}5.点击退出登录,直接让数据为空就行
//退出登录
loginOut() {
wx.removeStorage({
key: 'userInfo',
success: () => {
this.setData({
userInfo: {}
})
}
})
}边栏推荐
- 线性代数学习笔记6-3:行列式的计算、代数余子式
- 国际权威认可!OceanBase入选Forrester Translytical数据平台报告
- OK-MY TODO LIST
- Linear Algebra Study Notes 4-5: Solving Systems of Linear Equations
- [Graduation Project] Automatic gas station refueling system based on STM32 - Internet of Things, microcontroller, embedded
- 洛谷P2412 查单词
- This指向问题
- happens-before规则与线程单例安全习题
- Detailed explanation of C51 basic functions, interrupt functions and library functions
- 谭浩强第五版第三章课后习题
猜你喜欢
随机推荐
BPAAS化建设实践-基本流程篇
Go语言 | 05 Template学习
《国际学术论文写作与发表》参考答案
国际权威认可!OceanBase入选Forrester Translytical数据平台报告
线性代数学习笔记4-4:求解非齐次线性方程组Ax=b,从秩的角度看方程
乘势而上,OceanBase推动数字支付精益增长
无聊的冷知识4
Linear Algebra Study Notes 3-4: Describe the spatial compression of linear transformations (column space, rank)
IDEA右键不能创建有参构造,狗血!
实现串口通信数据帧打包与解析,串口通信可靠传输,屡试不爽的数据封包与状态机数据解析程序
洛谷P1202 黑色星期五Friday the Thirteenth
动态规划之背包问题
把back-ground-color改为以驼峰命名法则形式backGroundColor
跨境电商如何通过打好数据底座,实现低成本稳步增长
向量化引擎对HTAP的价值与技术思考
富滇银行完成数字化升级|OceanBase数据库助力布局分布式架构中台
线性代数学习笔记4-6:矩阵的零空间、列空间、行空间、左零空间、初等行变换、测验题
推荐抓包工具
Linear algebra learning notes 4-2: understanding of the system of linear equations, gaussian elimination, LU decomposition
STC不同系列单片机的软串口位时间函数差异









