下面是nav组件代码
<view class='wrap'>
<view class='ul'>
<view class='li' wx:for="{{urlList}}" wx:key="key" wx:for-index="idx">
<navigator data-active="{{idx}}" bindtap="onTap" redirect="true" open-type="navigate"
class='item {{active == idx ? "other-navigator-hover" : ""}}'
url='{{"./../" + item.url + "/" + item.url}}'>{{item.txt}}</navigator>
</view>
</view>
</view>
这里是nav组件Js
properties: {
active: Number
},
methods: {
onTap: function (e) {
wx.setStorageSync("navActive", e.target.dataset.active)
console.log(wx.getStorageSync('navActive'))
}
}
下面是页面代码了
<topNav active="{{topNavActive}}"></topNav>
页面JS
data: {
topNavActive:null
}
onLoad: function () {
let that = this
let acNum = wx.getStorageSync("navActive")
that.setData({
topNavActive: acNum
})
}
在开发者工具上面active没问题,在手机上调试就出现问题了,getStorage的时候回出现get到上次的数字导致active class 还是回到上个导航那里。
已找到解决方案,不能用导航标签,直接用view绑定方法跳转。