[Vuejs]-How can I use data defined in data() in other methods in Vue js?

0👍

First of all, use created() instead of mounted() for calling methods that fetch data.

Next, you need to call getNames() only after all fetch methods complete.

created() {
this.getTypes()
  .then(this.getSeverities())
  .then(this.getStatuses())
  .then(this.getNames());
}

In order to chain methods like this you need to put return statement before each axios like this

  getTypes() {
  return axios
    .get("https://fadiserver.herokuapp.com/api/v1/my-types")
    .then((response) => {
      this.Types = response.data;
    })
    .catch((error) => {
      console.log(error);
    });
}

In this component, I see you are receiving issuesList and index props from the outside. I cannot know those values but you can console.log both of them inside created() and see what is happening because issuesList[index] is undefined.

That probably means issuesList is an array and that index does not exist in that array.

Leave a comment