【问题标题】:import Vue component and update content via axios通过 axios 导入 Vue 组件并更新内容
【发布时间】:2018-11-10 12:47:30
【问题描述】:

我有两个文件,一个是 .js,其中仅注册了 vue 组件,第二个我有带有脚本的 vue 模板。我想在单击某个元素后更新信息,即我收到的来自 axios 的数据,但我不知道如何将这些数据解析为我想要打印数据到模板的数组。

代码是HERE

错误是:TypeError: Cannot set property 'currentLog' of undefined

【问题讨论】:

    标签: javascript arrays laravel parsing vue.js


    【解决方案1】:

    那是因为你的 searchUser 函数在 vue 实例之外,因此 'this' 没有引用它。 尝试将 searchUser 放入方法中,然后您需要使用 this.searchUser 调用它。

    编辑:您的数据定义错误,应该是:

    data() {
            return {
                currentLog: {}
           }
    }
    

    【讨论】:

    • 我试过了,还是不行,同样的问题。还有其他想法吗?
    • 该函数调用良好,但无法将数据保存到currentLog。当我在这个函数中写入console.log(response.data); 数据被打印
    • 谢谢,当我将它移入方法时,我必须在 searchUser 中写入什么?因为当我在那里 this.currentLog = response.data; 它什么都不做
    • 为什么我不能从方法 searchUser() 保存到数组中,但从 created() 方法可以工作?
    【解决方案2】:

    已解决:

    问题出在函数 searchUser 中,当我通过 GET 从 axios 获取数据后将数据保存到数组中。

    将“函数”替换为“=>”

    正确的是HERE

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-11-10
      • 2020-11-24
      • 2019-09-24
      • 1970-01-01
      • 1970-01-01
      • 2020-12-03
      • 2020-02-28
      • 2019-11-25
      相关资源
      最近更新 更多