代码
提交代码
function chooseClubItem(e) { let mid = e.currentTarget.dataset.id let findAddressInfo = this.data.markers.find(item => item.id === mid) const historyList = window.localStorage.getItem('historyList') || []//获取localstorage需要操作的键值 if (findAddressInfo) { const index = historyList.findIndex(history => history.id == findAddressInfo.id) if (index !== -1) { historyList.splice(index, 1) } if(historyList.length>=10)historyList.pop();//超过最大历史数目,删除最后一个 historyList.unshift(findAddressInfo)//加入到历史存储队列中 window.localStorage.setItem('historyList', historyList)//设置离线存储 } },
运行结果