一、 localStorage裡面的方法
localStorage.setItem(key,value)
localStorage.getItem(key)
localStorage.removeItem(key);
localStorage.clear();
二、封裝localStorage
1、新建models/storage.js
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;
2、引入
import storage from './model/storage.js';
本作品採用《CC 協議》,轉載必須註明作者和本文連結