[Vuejs]-Assign data to variable with event received data

0👍

Reading your comments with @Satyam, maybe a watcher could help?

watch: { 
  order() {
    if(this.order && this.order.BillNo)
      this.doSomethingWith(this.order.BillNo) // callback
    }
}

0👍

The solution depends on what you want to do with the data. The primary "problem" is that you are working here with asynchronous call.

 mounted() {
            Fire.$on('orderId', (id) => {
                axios.get('/api/order/'+id).then(({data}) => {
                this.order = data.order;
                this.orders_details = data.order_details;
                    console.log(this.order.BillNo) // fires after the request
                 });
            });
            console.log(this.order.BillNo) // fires immediately bevor request
        },

In most cases the following will be the solution:

<div v-if="order">...</div>
<my-loader v-else/>

Leave a comment