代碼
提交代碼
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)//設置離線存儲
}
},
運行結果