0

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,

1 Answer 1

2
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))
Sign up to request clarification or add additional context in comments.

1 Comment

Likely a copy-paste error here. Otherwise, a syntax error would stop the OP from even running the code.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.