dimanche 31 octobre 2021

How do I use local storage PLUS API in Vue version 2?

I'm trying to make a to-do list where the list is filled with tasks from an asynchronous query. I also want to add tasks and have them saved to my local storage. However, when I mount the local storage below mounting the API, the API disappears. When I put them both in the same mount, the local storage part doesn't work. What am I doing wrong?

var app = new Vue({
  el: '#app',
  data () {
    return {
      items: [{
        title: "",
        completed: false,
        }],
        title: '',
        show: 'all',
    }
  },
  mounted () {
    axios
    .get("https://jsonplaceholder.typicode.com/todos")
    .then(response => this.items = response.data)
  },
  mounted () {
    if(localStorage.item) this.item = localStorage.item;
  },



Aucun commentaire:

Enregistrer un commentaire