saveHistory(){// 获取缓存数据let historyArr = uni.getStorageSync('historyArr') || []//需要添加的数据let item={id:this.detail.id,classid:this.detail.classid,title:this.detail.title,picurl:this.detail.picurl,looktime:parseTime(Date.now())};// forEach和findIndex的区别:forEach会循环数组,但是不会有返回值,可以在循环中做与返回值无关的数组处理,// findIndex也会循环数组,会有return处理,当return的值为true时会返回第一个为true的数据项的indexlet index = historyArr.findIndex(i=>{// 返回第一个匹配到的值的索引return i.id == this.detail.id})// 如果该索引>0,就说明数组内已经有这个浏览记录了if(index>=0){// 删除元素,第一个参数为开始处理的下标// 第二个元素为,你要删除几个元素historyArr.splice(index,1)}// 将需要添加到数据追加在缓存数据的最前面historyArr.unshift(item);// 重写写入缓存uni.setStorageSync('historyArr',historyArr)}