data () {
return {
report: ''
}
},
methods:{
fetchCustomers(){
this.$axios.get("http://api.xxxx.com/admin/report")
.then(function(response){
console.log(response.data)
this.report = response.data;
console.log(this.report)
})
.catch(function (error) {
if (error.response) {
// 请求已发出,但服务器响应的状态码不在 2xx 范围内
console.log(error.response.data);
console.log(error.response.status);
console.log(error.response.headers);
} else {
// Something happened in setting up the request that triggered an Error
console.log('Error', error.message);
}
console.log(error.config);
});
}
}
总是提示说没有定义这个属性,请问这个是什么问题,TKS
this.report = response.data;
这里this
没有指向 Vue 实例.回调函数改成箭头函数; 或者在
fetchCustomers
函数顶部let that = this
保存 this 指向, 然后that.report = response.data;