我无法删除 localStorage 中的项目。我创建了一个表来存储添加的项目。我想通过索引或 ID(如果可能)删除一篇文章。谢谢你的帮助
deleteOption(){
this.test = JSON.parse(localStorage.getItem('test'))
this.test.splice(index, 1)
},
test:[
{
id:1,
item: test item 1
},
{
id:2,
item: test item 2
},
{
id:3,
item: test item 3
},
]
addItem () {
localStorage.setItem("test",JSON.stringify(this.test))
}
最佳答案
localstorage getItem
方法返回一个应解析为数组的字符串:
this.test = JSON.parse(localStorage.getItem('test'))
this.test.splice(index, 1)
关于javascript - 按索引删除 localStorage vuejs 数组中的文章,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67711808/