NavigateTo wx. NavigateTo add a listening event to get
1. The scene
Wx. navigateBack() in the small program does not return with parameters, but in our e-commerce business, click to select the user’s shipping address, click the user information, need to return to the superior and bring the user ID.
2. Initial page code
index.wxml
<l-button bind:lintap="enterDetail">Copy the code
index.js
Wx. NavigateTo ({url: '.. /detail/detail', }) }, onShow: function () { var pages = getCurrentPages(); var currPage = pages[pages.length - 1]; Console. log(currpage.data.id)},Copy the code
3. Destination page
detail.html
<l-button bind:lintap="sendParams"> </l-button>Copy the code
detail.js
sendParams(){
let pages = getCurrentPages();
let prevPage = pages[pages.length - 2];
let id = this.data.id;
prevPage.setData({
id: 1,
})
setTimeout(() => {
wx.navigateBack({})
}, 500)
},
Copy the code
Results 4.
After clicking to enter details, return to page console to print 1