[Vuejs]-Uncaught (in promise) TypeError: Cannot set property of undefined at eval in vue.js?

2👍

The arrow function is to blame, I believe. Convert getAllItemsFromDb to a function function:

methods: {
   getAllItemsFromDb() {
      const url = 'https://localhost:44339/ListAll';

      axios.get(url, {
         headers: {
            'Content-Type': 'application/json'
         }
      }).then((response) => {
         this.itemListModel = response.data
      })
   }
}
👤mbojko

1👍

In your getAllItemsFromDb function you are awaiting the result of axios.get(). As a result you don’t need the .then() block. Try this:

getAllItemsFromDb: async () => {
  const url = 'https://localhost:44339/ListAll';
  const response = await axios.get(url, {
    headers: {
      'Content-Type': 'application/json'
    }
  });

  this.itemListModel = response.data;
}
👤Malice

Leave a comment