Home > Blockchain >  Vuejs3 and AXIOS update variable
Vuejs3 and AXIOS update variable

Time:12-25

I call a POST function with AXIOS and I want to retrieve a JSON dict from it. I don't find how to update my Vuejs 3 variable.

    <script type="text/javascript">
    Vue.createApp({
      data() {
        return {
          name: 'Vue.js',
          accounts: "",
        }
      },
      methods: {
        refresh_account_list(event) {
          axios.defaults.xsrfHeaderName = "X-CSRFTOKEN";
          axios.defaults.xsrfCookieName = "csrftoken";
          axios.defaults.withCredentials = true;
          axios.post('/api/gads/get_accounts', {
            mcc_id: 'XXXXXXXX',
          }) => (this.accounts = response.data)
        }
      }
    }).mount('#app')
    </script>

The value of "accounts" never changes, even if I receive data correctly. Did I miss something ?

Many thanks,

CodePudding user response:

axios.post('/api/gads/get_accounts', {
  mcc_id: 'XXXXXXXX',
}) => (this.accounts = response.data)

This is actually a wrong syntax. It should be looking like this:

axios.post('/api/gads/get_accounts', {
  mcc_id: 'XXXXXXXX',
}).then(response => (this.accounts = response.data))
  • Related