The overall idea: put the parameters that need to be passed into the global js.
1. Define global parameters: in app.js:
globalData: {
isSaveRecord: 0, //我自己的默认值
search: '', //我自己的默认值
},
2. The path in the first page contains parameters, but the url here does not support queryString, so put the parameters in the global js:
var app = getApp()
Page({
// 真实路径:url: '../../second/index/second?
// isSaveRecord='+isSaveRecord+'&search='+search
// 给全局参数赋值
app.globalData.isSaveRecord = 1
app.globalData.search = value
wx.switchTab({
url: '../../second/index/second'
})
3. Get the parameters on the next page:
var app = getApp()
Page({
onShow: function(e) {
var that = this
// 获取全局参数,在上一个页面赋值的
var isSaveRecord = app.globalData.isSaveRecord;
var search = app.globalData.search;
//判断是否带参数,带的话执行里边逻辑
if (search != null || search != '' || search != undefined) {
//设置到页面data中,其他地方就可以使用了
that.setData({
searchContent: search,
isSaveRecord :isSaveRecord
});
}
// 记得,一定要还原全局数据
app.globalData.isSaveRecord = 0
app.globalData.search = ''
},
省略.....
})