lengziyu / noteBook

This is my noteBook.
0 stars 0 forks source link

localStorage操作与封装 #15

Open lengziyu opened 7 years ago

lengziyu commented 7 years ago

封装:

// 储存localStorage
function setlocalStorage(storeName, storeData) {
    var storeStr = JSON.stringify(storeData);
    var storeArr = window.localStorage.setItem(storeName, storeStr);
    return storeArr;
}
//调用
setlocalStorage('userInfo', data);
// 获取localStorage
function getlocalStorage(storeName) {
    var storeName = localStorage.getItem(storeName);
    var storeArr = JSON.parse(storeName)
    return storeArr;
}
getlocalStorage('userInfo');

删除:

localStorage.removeItem('userInfo');