十年河東,十年河西,莫欺少年窮
學無止境,精益求精
wxml: 開放能力:獲取用戶信息 及 獲取用戶手機號
<van-dialog id="van-dialog" bind:confirm="confirm" bind:getuserinfo="getuserinfo" bind:getphonenumber="getphonenumber"/>
page.json 引入組件
{ "usingComponents": { "van-dialog": "@vant/weapp/dialog/index" } }
page.JS
// pages/userInfo/userInfo.js/ import Dialog from '../../miniprogram_npm/@vant/weapp/dialog/dialog'; Page({ /** * 頁面的初始數據 */ data: { }, /** * 生命周期函數--監聽頁面加載 */ onLoad: function (options) { this.GetUser(); }, GetUser(){ let that=this; Dialog.alert({ title: '登錄', message: '是否公開您的信息', confirmButtonOpenType:"getUserInfo", // 按鈕的微信開放能力 showCancelButton:true, confirmButtonText:"授權登錄" }).then(() => { }).catch(()=>{ }); }, confirm(){ console.log('confirm') }, /**授權-新接口 */ getuserinfo(e) { console.log(e) wx.setStorageSync('userInfo', e.detail.userInfo) // wx.getUserInfo的返回兼容 wx.setStorageSync('encryptedData', e.detail.encryptedData) wx.setStorageSync('iv', e.detail.iv) //拿到用戶信息后 獲取 用戶手機號 this.GetUserPhone(); }, GetUserPhone(){ let that=this; Dialog.alert({ title: '登錄', message: '是否允許獲取您的手機號', confirmButtonOpenType:"getPhoneNumber", // 按鈕的微信開放能力 showCancelButton:true, confirmButtonText:"授權" }).then(() => { }).catch(()=>{ }); }, getphonenumber(e){ console.log(e) } })
@天才卧龍的博客