[Vuejs]-Update array localstorage with vanilla

1πŸ‘

βœ…

I think the problem here, is Vue is not watching your localStorage so it has no idea when to update.
If you need to use your localStorage, you should let Vue know whether it has changed or not. Something like..

...
  data() {
    return {
      yourList: []
    }
  }
...
 methods: {
    removeItem (clickedId) {
      this.yourList = this.yourList.filter((item) => item.id !== clickedId);
      localStorage.setItem("items_ids", JSON.stringify(this.yourList));
    }
  },

So in this code we’re not controlling data from localStroage. We control reactivity data which is yourList and just keep updating localStorage manually

πŸ‘€Ikhyeon Kim

Leave a comment