【避坑指“难”】小程序wx.navigateTo带参数路由跳转,跳转后获取参数

577 阅读1分钟

当进行页面跳转的时候,要将一些基本信息一起带到跳转后的详情页,这时候我们就得把参数添加到路由跳转链接上

index.js

<cover-view wx:if="{{isPicture}}"  data-id="{{picUrl}}" bindtap="handleJumpto" class='jump-item' >
</cover-view>

data-id 绑定参数为picUrl(这里指的是图片链接)

  handleJumpto(e){
  	consolo.log('e',)
    var that = this
    const temp = e.currentTarget.dataset.id
    wx.navigateTo({
      url: './photo-detail/photo-detail?picUrl=' + temp 
    })
  }

跳转到picture.js

  onLoad(options) {
    console.log('options',options) 
    this.setData({
      picUrl: options.picUrl,
    })
  },
<image class="image" src="{{picUrl}}" mode="widthFix" >  </image>