onLoad(options) {
this.storeBindings = createStoreBindings(this,{
store,
fields:['checkNum'],
actions:[]
})
//console.log(this.authFailed)
},
checkNum这个值,在WXML中使用正常:
<block wx:if="{{checkNum}}">
……
block>
但是我想在.js文件中使用一下该值,用来做个判断,为其他的值赋值:
if(!this.checkNum) {
wx.showToast({
title: '设置错误',
icon:'error'
})
}
就总是说checkNum是not defined。但是如果我在data中define这个值,就又不是共享数据中的那个值了。
在app.js中设置全局变量。在组件里面使用以下方式取全局变量。
const app = getApp()
console.log(app.globalData.userInfo);
全局变量 globalData 应该可以吧