鍍金池/ 問答/HTML/ 小程序Storage正確使用方法?

小程序Storage正確使用方法?

下面是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
    })
  }

在開發(fā)者工具上面active沒問題,在手機(jī)上調(diào)試就出現(xiàn)問題了,getStorage的時(shí)候回出現(xiàn)get到上次的數(shù)字導(dǎo)致active class 還是回到上個(gè)導(dǎo)航那里。

回答
編輯回答
離殤

已找到解決方案,不能用導(dǎo)航標(biāo)簽,直接用view綁定方法跳轉(zhuǎn)。

2017年9月6日 10:46