【问题标题】:Vuejs3 and AXIOS update variableVuejs3 和 AXIOS 更新变量
【发布时间】:2022-01-24 20:09:16
【问题描述】:

我用 AXIOS 调用了一个 POST 函数,我想从中检索一个 JSON 字典。我找不到如何更新我的 Vuejs 3 变量。

    <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>

即使我正确接收数据,“帐户”的值也不会改变。 我错过了什么吗?

非常感谢,

【问题讨论】:

    标签: vue.js axios vuejs3


    【解决方案1】:
    axios.post('/api/gads/get_accounts', {
      mcc_id: 'XXXXXXXX',
    }) => (this.accounts = response.data)
    

    这实际上是一个错误的语法。它应该是这样的:

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

    【讨论】:

    • 这里可能出现复制粘贴错误。否则,语法错误甚至会阻止 OP 运行代码。
    猜你喜欢
    • 2021-09-16
    • 2022-06-19
    • 1970-01-01
    • 2015-02-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-27
    • 2023-01-27
    相关资源
    最近更新 更多