[Vuejs]-Vuejs can't refer to array

4👍

It is showing you undefined because the console.log is outside the promise. When you console log it ref_number_response is an empty array and the first element is clearly undefined.

data(){
     return { 
           ref_number_response: [],
     };
},
methods: {
   check_ref_number() {
             // axios request
             axios.get('/is_referenceNumber_free/'+this.ref_number)
             .then((response) => {
                  console.log(response.data);
                  this.ref_number_response = response.data;
                  console.log(this.ref_number_response); // now its not empty
                  this.$emit('reference_added', this.ref_number_response);
             });
         },
}

Leave a comment