html5本地存储封装(可存储数组对象)

function MenuList(){
   this.menuList=menuList;
    return this;
}

MenuList.prototype={

  add:function(dataval){
      this.dataval=dataval || [];
     localStorage.setItem(this.menuList,JSON.stringify(this.dataval));
  },
  get:function(){
     return JSON.parse(localStorage.getItem(this.menuList));
  },
  remove:function(){
     localStorage.removeItem(this.menuList);
  },
  clear:function(){
     localStorage.clear();
  }

};

使用示例:

const menuList=new MenuList();

menuList.add(data.menuList);

猜你喜欢

转载自blog.csdn.net/qq_26522773/article/details/79308752