赞
踩
var storage = {
set(key, value){
localStorage.setItem(key,JSON.stringify(value));
},
get(key){
return JSON.parse(localStorage.getItem(key));
},
remove(key){
localStorage.removeItem(key);
}
}
export default storage;
这个方法比较简陋,用下面这个功能较为完整的
var storage = { set(key, value) { if (typeof value === "object") { value = JSON.stringify(value); } localStorage.setItem(key, value); }, get(key) { const data = localStorage.getItem(key); try { return JSON.parse(data); } catch (err) { return data; } }, remove(key) { localStorage.removeItem(key); }, }; export default storage;
storage.set('answerItems',this.answer.answerItems)
前面是需要更新的键名,后面是需要更新键名的值
写一个method方法:
readUpdateVal() {
storage.set("answerItems", this.answer.answerItems);
},
注意:
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。