代碼
提交代碼
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();//超過(guò)最大歷史數(shù)目,刪除最后一個(gè)
historyList.unshift(findAddressInfo)//加入到歷史存儲(chǔ)隊(duì)列中
window.localStorage.setItem('historyList', historyList)//設(shè)置離線存儲(chǔ)
}
},
運(yùn)行結(jié)果