I am currently working on developing a simple to-do app with vue.js. My goal is to save the to-dos stored in an array so that they persist even after resetting the site. After browsing through some documentation, I came across the following solution:
data() {
return {
array: [
{id: 1, label: 'learn vuejs'},
]
}
},
methods: {
persist() {
localStorage.array = this.array;
alert('items saved')
}
},
mounted() {
if (localStorage.array && localStorage.array.id) {
this.array = localStorage.array;
this.array[id] = localStorage.array.id;
}
},
Although this code successfully saves the array to localStorage, it fails to capture the objects within the array. Upon checking localStorage in the console, the output is as follows:
array: "[object Object]"
If anyone has a solution to saving the items within the array, please provide detailed instructions.