|
5 | 5 | <view style="background:#FFF; padding:40upx;"> |
6 | 6 | <block v-if="hasUserInfo === false"> |
7 | 7 | <view class="uni-hello-text uni-center"> |
8 | | - <text>请点击蓝色按钮获取用户头像及昵称</text> |
| 8 | + <text>请点击下方按钮获取用户头像及昵称</text> |
9 | 9 | </view> |
10 | 10 | </block> |
11 | 11 | <block v-if="hasUserInfo === true"> |
|
20 | 20 | <button type="primary" @tap="getUserInfo">获取用户信息</button> |
21 | 21 | <!-- #endif --> |
22 | 22 | <!-- #ifdef MP-WEIXIN --> |
23 | | - <button type="primary" open-type="getUserInfo" @getuserinfo="wxGetUserInfo">获取用户信息</button> |
| 23 | + <button type="primary" open-type="getUserInfo" @getuserinfo="mpGetUserInfo">获取用户信息</button> |
| 24 | + <!-- #endif --> |
| 25 | + <!-- #ifdef MP-BAIDU --> |
| 26 | + <button type="primary" open-type="getUserInfo" @getuserinfo="mpGetUserInfo">获取用户信息</button> |
24 | 27 | <!-- #endif --> |
25 | 28 | <button @tap="clear">清空</button> |
26 | 29 | </view> |
|
46 | 49 | loginProvider: state => state.loginProvider |
47 | 50 | }) |
48 | 51 | }, |
49 | | - onLoad: function () {}, |
| 52 | + onLoad: function() {}, |
50 | 53 | methods: { |
51 | 54 | getUserInfo() { //获取用户信息api在微信小程序可直接使用,在5+app里面需要先登录才能调用 |
52 | 55 | uni.getUserInfo({ |
|
63 | 66 | content = "请在登录页面完成登录操作" |
64 | 67 | } |
65 | 68 | uni.showModal({ |
66 | | - title:"获取用户信息失败", |
67 | | - content:"错误原因"+content, |
| 69 | + title: "获取用户信息失败", |
| 70 | + content: "错误原因" + content, |
68 | 71 | showCancel: false |
69 | 72 | }) |
70 | 73 | } |
71 | 74 | }) |
72 | 75 | }, |
73 | | - wxGetUserInfo(e){ |
| 76 | + mpGetUserInfo(e) { |
74 | 77 | console.log("得到用户信息", e); |
75 | | - if(e.detail.errMsg !== 'getUserInfo:ok'){ |
| 78 | + if (e.detail.errMsg !== 'getUserInfo:ok') { |
76 | 79 | uni.showModal({ |
77 | | - title:"获取用户信息失败", |
78 | | - content:"错误原因"+e.detail.errMsg, |
79 | | - showCancel:false |
| 80 | + title: "获取用户信息失败", |
| 81 | + content: "错误原因" + e.detail.errMsg, |
| 82 | + showCancel: false |
80 | 83 | }); |
81 | 84 | return; |
82 | 85 | } |
83 | 86 | this.hasUserInfo = true; |
84 | 87 | this.userInfo = e.detail.userInfo |
85 | 88 | }, |
86 | 89 | clear() { |
87 | | - this.hasUserInfo = false, |
88 | | - this.userInfo = {} |
| 90 | + this.hasUserInfo = false; |
| 91 | + this.userInfo = {}; |
89 | 92 | } |
90 | 93 | } |
91 | 94 | } |
|
97 | 100 | width: 128upx; |
98 | 101 | height: 128upx; |
99 | 102 | } |
100 | | -</style> |
| 103 | +</style> |
0 commit comments