1. 程式人生 > 實用技巧 >uniapp 開發微信小程式總結(四)mixin - login

uniapp 開發微信小程式總結(四)mixin - login

在這個專案中,呼叫登入介面時,將頁面引數傳入,且登入完成後需要呼叫別的介面。

 1 import {mapState,mapActions,mapMutations,mapGetters} from 'vuex'
 2 export default {
 3     computed:{
 4         ...mapState('login',['userInfo','inviteUserId','guidecode']),
 5         ...mapGetters('login',['isLogin']),
 6         getBinding(){
 7             if
(this.isLogin&&(this.inviteUserId||this.guidecode)){ 8 console.log('bindWithGuid...') 9 this.bindWithGuid({}) 10 } 11 return this.isLogin 12 } 13 }, 14 onLoad(options){ 15 console.log('mixin onload...') 16 let _this = this
17 let {inviteUserId} = options 18 if(inviteUserId){ 19 console.log('inviteUserId:' + inviteUserId) 20 this.GETINVITEUSERID({inviteUserId}) 21 } 22 if(!this.isLogin){ 23 // 微信小程式登入 24 uni.getSetting({ 25 success: function
(t) { 26 if(t.authSetting["scope.userInfo"]){ 27 _this.onGetUserInfo() 28 } 29 } 30 }) 31 } 32 }, 33 methods:{ 34 ...mapMutations('login', ['GETINVITEUSERID']), 35 ...mapActions('login',['bindWithGuid','onGetUserInfo']), 36 } 37 }