Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ankurgoel's avatar

Value not updating from axios response in vue

I am not able to update the object temp after the axios call.

Please help.

This is whole code. I have used the component in vue. I am very new to vue and components.

I have modified the code. Please check again. I am using the component. Moreover in the Vue tab of the Chrome developer tools i am only seeing component as Root not able to see Shipping Address other component inside the root.

Below is app.js

require('./bootstrap');

window.Vue = require('vue');

import axios from 'axios';
window.axios = axios;

Vue.component('shipping-address', require('./components/ShippingAddress.vue'));

const app = new Vue({
    el: '#app',
});
export default app;
<div id="app">
    <shipping-address ></shipping-address>
</div>
<template>
  <div>
    SName: <span>{{temp}}</span>                    
  </div>
</template>
<script>
export default {
  data(){
    return{
        temp:'a'
    }
  },
  mounted(){
      this.fetchArticles();
  },
  methods:{
      fetchArticles() {
          this.temp = 'b'
          const vm = this;
            axios.get('user/addresses')
            .then(response=>{this.temp = 'c';})
            .catch( error => console.log(error));
        },
  }
}
</script>
0 likes
4 replies
nolros's avatar
nolros
Best Answer
Level 23

@ankurgoel a couple of observations assuming this is inside of a Laravel app. I think you are attempting to run it as a Vue app, but then again your code wouldn't work either.

  1. add default
Vue.component('shipping-address', require('./components/ShippingAddress.vue'));

to

// append default or it wont show
Vue.component('shipping-address', require('./components/ShippingAddress.vue'), default);
  1. Also, remove this from app.js

export default app;

  1. add name to you shipping address components
export default {
   name: "ShippingAddress"
  data(){
    return{
        temp:'a'
    }
  },
/// removed the rest for brevity sake
}

ankurgoel's avatar

Thanks everyone. I am very new to the vue so please ignore my silly mistake.

Actually in my project i included app.js 2 times so it was not working properly.

I spent 2 days then i got to know. I created new project and started from scratch and get to know about the issue.

Thanks @nolros & @usmanbasharmal for your time.

2 likes
aman5440's avatar

@ankurgoel O bhai... same maine bhi kiya... thanks for your precious update on own question

Please or to participate in this conversation.