【发布时间】:2017-09-12 05:39:56
【问题描述】:
我正在尝试使用 Vue 组件来访问它,但我发现错误状态未定义,这是我的 Vue 组件
<script>
export default {
mounted() {
axios.get('/userfound/' + this.profile_user_id)
.then(function (response) {
console.log(response);
this.status = response.data.status;
})
.catch(function (error) {
console.log(error);
});
},
props: ['profile_user_id'],
data(){
return {
status: ''
}
},
methods:{
add_friend(){
// this.loading = false
axios.get('/add_friend/' + this.profile_user_id)
.then(function (response) {
console.log(response);
if (response.data == 1) {
this.status = 'waiting'
}
})
.catch(function (error) {
console.log(error);
});
}
}
}
</script>
为什么会出现此错误:TypeError: cannot read property 'status' of undefined ..
我试过 "this.status = response.body.status" 和 "this.status = response.data.status" 但都没有工作
【问题讨论】:
标签: json vuejs2 laravel-5.4 vue-component