微信小程序wx.switchTab参数处理

官方文档上不能传递参数。

所以只能放在全局变量中。

app.js中

 globalData: {
    homeCurrentTab:0
  }

我们所在的页面:

.wxml内容:navigator必须要有url参数

<navigator  bindtap='kind' url='../kind/kind' open-type="switchTab" data-id="0">
      <view ">跳转</view>
    </navigator>

kind方法为:将data-id="0"中的数据作为全局参数保存getApp().globalData.homeCurrentTab

  kind: function (e) {
   getApp().globalData.homeCurrentTab = e.currentTarget.dataset.id;
    console.log("kind", e.currentTarget.dataset.id);
  },

跳转后的页面:

onShow: function (e) {
    this.data.currentTab = getApp().globalData.homeCurrentTab;
    console.log("switch", this.data.currentTab)
    var self = this
    self.setData({
      currentTab: this.data.currentTab
    })
  },

猜你喜欢

转载自blog.csdn.net/qq_39404258/article/details/90481145