使用VUE.js在LocalStorage中存储对象

时间:2019-06-03 10:00:38

标签: javascript

我需要存储一个名为Projects的对象,该对象包含Teams,每个Team都包含用户,所有这些用户都没有表或其他sql东西,全部都存储在本地存储中,然后需要对它们和所有东西进行CRUD。有任何想法吗?

project = JSON.parse(localStorage.getItem('projects'));
console.log(project);
project.push(this.projectname);    
localStorage.setItem("projects",JSON.stringify(project));

1 个答案:

答案 0 :(得分:0)

您可以使用对象数组,如下所示:

var user1 = {"name":"user1"}; //Object1
var user2 = {"name":"user2"}; //Object2
var team = []; //array of objects
team.push(user1);
team.push(user2);
var projects = [];
projects.push(team);
console.log(projects); //store this into localstorage