SearchVal (val) {
      val = val.trim() // 清除空格
      if (this.HistoryList.length > 0) { // 有数据的话 判断
        if (this.HistoryList.indexOf(val) !== -1) { // 有相同的,先删除 再添加 
          this.HistoryList.splice(this.HistoryList.indexOf(val), 1)
          this.HistoryList.unshift(val)
        } else { // 没有相同的 添加
          this.HistoryList.unshift(val)
        }
      } else { // 没有数据 添加
        this.HistoryList.unshift(val)
      }
      if (this.HistoryList.length > 6) { // 保留六个值
        this.HistoryList.pop()
      }
      localStorage.setItem('HistoryList', JSON.stringify(this.HistoryList))
    }

 

Logo

前往低代码交流专区

更多推荐