요청을 보내고 이에 근거한 응답을 받고 싶습니다. 상태를 확인하고 다른 것을 표시하고 싶습니다. 문제가 무엇인지 알 수 없습니다. 경로가 잘 작동하는 것 같고 다음과 같은 응답을 받고 있습니다.
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"
있지만, 어느 쪽도 노력하고 있습니다
변수의 범위에 문제가 있다고 생각합니다. 아래 답변을 시도하십시오.
<script>
export default {
mounted() {
var self = this;
axios.get('/userfound/' + self.profile_user_id)
.then(function (response) {
console.log(response);
self.status = response.data.status;
})
.catch(function (error) {
console.log(error);
});
},
props: ['profile_user_id'],
data(){
return {
status: ''
}
},
methods:{
add_friend(){
// you can do same here as well
var self = this;
axios.get('/add_friend/' + self.profile_user_id)
.then(function (response) {
console.log(response);
if (response.data == 1) {
self.status = 'waiting'
}
})
.catch(function (error) {
console.log(error);
});
}
}
}
</script>
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다