是否是要用到接口来做呢,要用wx.request吗,麻烦能用代码讲解吗?
全局参数例子:
https://developers.weixin.qq.com/s/CMccoXmN7TBz
在app.js定义字段
App({
// 全局定义支出字段
expenditure: 100,
})
index.js
Page({
data: {
expenditure: 0
},
onShow() {
this.setData({ expenditure: getApp().expenditure })
}
})
index.wxml
<view>支出:{{expenditure}}元</view>
<navigator url="/index1/index">去index1</navigator>
index1.js
Page({
data: {
expenditure: 0
},
onShow() {
this.setData({ expenditure: getApp().expenditure })
},
pay100() {
this.setData({ expenditure: getApp().expenditure += 100 })
}
})
index1.wxml
<view>支出:{{expenditure}}元</view>
<view bindtap="pay100">支出100元</view>
你在app.js 中定义
App({
// 全局定义支出字段
paytomoney: 100,
})
如果是在app.js文件中,直接使用,如:
this.paytomoney
在其他非app.js文件中使用,需要先申明app变量,如:
var app = getApp()
app.paytomoney
如果要修改这个变量,应如下:
在app.js文件中:
this.paytomoney = 200
在其他非app.js文件中修改:
var app = getApp()
app.paytomoney =200
1,2次 request
2,用全局参数