问题 微信小程序如何实现跨页面传递参数呢
假设需要将B页面需要的数据从A页面传过去,如何进行呢?
解决
通过绑定事件自定义对象属性传参,也就是data-*
例如,在wxml页面有这些内容
<button bindtap="download" data-index='{{item.filePropagationPlanDetailID}}' ">点击</button>
/**item表示需要渲染的数组,数据需要填你自己需要的数据*/在js文件中
download: function (e){
// 这个 index 值就是要带走到B的参数
let index = e.currentTarget.dataset.index;
// 路由跳转并带参数(跳转到 B 页面)
wx.navigateTo({
  url: '../B/B?index =' + index 
})}
然后在B页面的data中声明index,例如
data:{
    index:””
}
接下来,在onload函数中
onload:function(options){
    console.log(options.index);
    wx.request({
    url: 'http://xxx/', 
    data: {
        id:options.index
    },
    header: {
    'content-type': 'application/json'
    },
    success (res) {
    console.log(res.data);
    }
})
}
      
      
- 本文作者: étoile
 
- 版权声明: 本作品采用 知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议 进行许可。转载请注明出处!