我想在其他页面渲染出score的值,全局好像不行啊
如何再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
回答:
//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里才能渲染
其他页面调用 :
this.setData({ score: app.globalData.score})