首页 > 编程知识 正文

python全局变量的声明和使用,全局变量是可以反复使用

时间:2023-05-06 19:02:08 阅读:274320 作者:3466

1:在App.vue中

要这样使用 ,let _this = this

在内部函数onShow,onLaunch等生命周期函数中要这样:

wx.getStorage({key: 'phoneNumber',success(res) {_this.$options.globalData.obtainChatAllow = true;_this.$options.globalData.obtainLikeAllow = true;_this.$options.globalData.obtainCallAllow = true;_this.$options.globalData.obtainMailAllow = true;_this.$options.globalData.obtainPhoneAllow = true;_this.$options.globalData.userPhone = res.data;}})

 

注意:在App.vue页面中的自定义函数中,如果加上$options会报错,所以要这样

//微信app用户绑定bindThird: function (phone) { const _this = this; let options = { url: "/applet/user/bindThird", params: { "phone": phone, }, successFn(res) { const data = res.data.data; _this.globalData.userToken = data.yunxinToken; _this.globalData.userAccId = data.accId; }, failFn(err) { _this.uni.toast("绑定用户失败,请重试"); console.log("绑定用户失败,请重试") } } return request(options);},

 

2:在其它页面使用 import app from "../../App.vue"created() {const _this = this;_this.dynamicIcon = app.globalData.headIcon;}

 

官网没去描述,这个坑踩得

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。