如何再wxml页面调用工具类utils里面的值?

小程序 文章 2021-12-14 17:20 471 0 全屏看文

AI助手支持GPT4.0

如何再wxml页面调用工具类utils里面的值?How to call the value in the tool class utils from the wxml page?

如何再wxml页面调用工具类utils里面的值?

我想在其他页面渲染出score的值,全局好像不行啊

I want to render the score value on other pages. It seems that the overall situation is not good

回答:

Lv: Max Human:
当然需要在小程序里提前调用一次util的方法。这样才能给app.globalData.score赋值,赋值成功后其他页面才能拿到

其他页面调用 :

this.setData({  score: app.globalData.score})
brave:
//app.jsApp({  globalData: {    BaseUrl: ""  },  getUserInfo(_that) {    let openid = wx.getStorageSync("openid")    wx.request({      url: this.globalData.BaseUrl + "getUserInfo",      data:{        id: openid      },      success: res => {        if (res.statusCode === 200 && res.data) {          //获取成功          _that.setData({            score: res.data.object.score          })        } else {          //获取失败        }      },      fail: err => {        //请求失败      }    })  }})// page.jsPage({  onLoad() {    getApp().getUserInfo(this)  }})
微喵网络:

只能在本页的js里才能渲染

沐清:可是我存到全局了呀,为啥渲染不出来
微喵网络:只能在本页的js里才能渲染

-EOF-

AI助手支持GPT4.0