收藏
回答

wx.removeStorageSync当时删除完毕,再次进去又会出现缓存的数据,删不掉吗?


先是有数据缓存,点击删除,的确当时没了

再次进去又会出现不明白是删不掉吗

Page({
 
  /**
   * 页面的初始数据
   */
  data: {
    searchRecord: []
  },
  openHistorySearch: function() {
    this.setData({
      searchRecord: wx.getStorageSync('searchRecord') || [], //若无储存则为空
    })
  },
  formSubmit: function(e) {
    console.log(e)
    let that = this
     var inputVal = e.detail.value
     wx.setStorage({
       key: 'uid',
       data: inputVal,
       success: function(res) {}
     })
    var searchRecord = this.data.searchRecord
    if (inputVal == '') {
      //输入为空时的处理
    } else {
      //将搜索值放入历史记录中,只能放前五条
      if (searchRecord.length < 5) {
        searchRecord.unshift({
          value: inputVal,
          id: searchRecord.length
        })
      } else {
        searchRecord.pop() //删掉旧的时间最早的第一条
        searchRecord.unshift({
          value: inputVal,
          id: searchRecord.length
        })
      }
      //将历史记录数组整体储存到缓存中
      wx.setStorageSync('searchRecord', searchRecord)
    }
 
  },
  historyDelFn: function(e) {
    console.log(e)
    wx.removeStorage('searhRecord')
    this.setData({
      searchRecord: []
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.openHistorySearch()
  },
 })



最后一次编辑于  2019-10-21
回答关注问题邀请回答
收藏

4 个回答

登录 后发表内容
问题标签