Bootstrap

微信小程序赋值传值,根据不同id跳转不同的页面

  1. data里声明变量
  data: {
    Roleid: ''
  },
  1. 赋值setData,这里直接从缓存中拿
  onLoad: function (options) {
    this.setData({
      Roleid: wx.getStorageSync('userinfo').role.role_id
    })
  },
  1. 页面上设置
    <view class="col-5 work_cart" bindtap="OpenCheck" data-Roleid="{{Roleid}}">
      <image src="/icons/icon11.png" mode="aspectFit"></image>
      <view>区域检查</view>
    </view>
  1. 取值判断把id传到跳转的页面中
  OpenCheck(e) {
    const roleid = e.currentTarget.dataset.roleid;
    if(roleid == 2){
      wx.navigateTo({
        url: '/pages/check_manager/index?role_id=' + wx.getStorageSync('userinfo').role.role_id,
      })
    }else{
      wx.navigateTo({
        url: '/pages/check/index?role_id=' + wx.getStorageSync('userinfo').role.role_id,
      })
    }

  },
;