- Pass value through url
First, call a click to detail method, mainly through wx.navigateTo of wechat API
toDetail: function(e){
var index = e.currentTarget.dataset.index; //Get subscript
var title = this.data.listDatas[index].title; //Get title
wx.navigateTo({ //Keep this page and jump to another page
url: '/pages/detail/detail?title='+title, //Pass url + value
})
}
Then the details page receives the value
onLoad: function (options) {
var title=options.title;
console.log('details'+title);
}
- Pass values by setting global variables
Set a global variable host in app.js
App({
onLaunch: function () {
},
globalData: {
userInfo: null,
host:'http://www.xzylogic.xyz/wx_Json_Img/bdy.json',
}
})
Then reassign in the method of jump details
toDetail: function(e){
var index = e.currentTarget.dataset.index; //Get subscript
var title = this.data.listDatas[index].title; //Get title
const app=getApp(); //Get app
app.globalData.host=title; /Copy the global variable again, and then extract the value in details
console.log(title);
}
- According to Tencent officials, the local cache can be set to 10MB
First pass the value, and call Tencent's APIwx.setStorage
// toDetail: Specifies the binding method on the wxml page
toDetail: function(e){
var index = e.currentTarget.dataset.index; //Get subscript
var title = this.data.listDatas[index].title; //Get title
wx.setStorage({ //Set local cache
key: "title",
data: title
})
wx.navigateTo({ //Keep this page and jump to another page
url: '/pages/detail/detail', //url + value of page path
})
},
Then get the cache in detail
onLoad: function (options) {
wx.getStorage({
key: 'title',
success: function(res) {
var title=res.data;
console.log('Value obtained: '+title);
},
})
}