Recently, I created a to-do list using Vue js and localstorage(LS). Everything was working fine until I tried to run it on a different browser where LS is not allowed. An error popped up saying
Cannot read property 'items' of null"
. The issue seems to be that I need to verify LS before utilizing it, but unfortunately, I am accessing LS in Data where checking it is not possible.
Below is an excerpt of my code:
var app = new Vue({
el: '.row',
data:{
cap:undefined,
ti:undefined,
forLS:{
items:[]
},
count:-1,
forLS:JSON.parse(localStorage.getItem("allData")),
count:JSON.parse(localStorage.getItem("count"))
}
I attempted to access LS within a function, but it seems impossible to execute it in Data. You can view the entire code HERE. I am struggling to find a solution to this problem. Thank you for any help in advance!