且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在vue.js中从axios获取响应数据

更新时间:2023-01-03 17:27:31

您的 this 指向回调中的错误对象.尝试使用箭头函数,闭包或 bind .

Your this is pointing to the wrong object in your callbacks. Try using an arrow function, a closure, or bind.

这里是使用箭头功能的示例.

Here is an example using an arrow function.

axios.get('/config/database')
        .then(response => {
            this.databaseConfiguration = response.data;
            console.log(response.data);
        })
        .catch(error =>{
            this.errors.push(error);
            console.log(error);
        })

请参见如何访问正确的 this 在回调中.

See How to access the correct this inside a callback.