D
D
Dauren S2021-06-30 23:24:20
Vue.js
Dauren S, 2021-06-30 23:24:20

Vue.js data fails to load?

methods: {
  async edit(id) {
      this.isEdit = 1;

     await axios
        .get(
          process.env.VUE_APP_API +
            "/" +
            this.api +
            "/" +
            this.module +
            "/" +
            this.submodule +
            "/retrieve/?id=" +
            id
        )
        .then((response) => {
          let data2=response.data[0];
          this.form.title = data2[2];
         
     
        
        })
        .catch((error) => {
          error;
        });
    },
},
  mounted() {
    setTimeout(() => {
       this.edit(this.$route.params.id);
    }, 1000);
  },

Unfortunately, you have to set timeout so that the data is loaded into the form, and without timeout, the inputs are empty. Please tell me how to do it without timeout, suddenly the data will arrive in 2 seconds or more.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Eduard Bazhenov, 2021-07-01
@kip_34

It is logical that the form is initially empty, because data arrives asynchronously. Check in the template if the data has arrived, for example, via v-if

0
0xD34F, 2021-07-01
@0xD34F Vue.js

watch: {
  данные: {
    immediate: true,
    handler() {
      if (данные) {
        делаете чего там вам надо
      }
    },
  },
},

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question