当我尝试添加朋友时,按钮正在加载并再次显示而不是等待响应,但刷新页面后它可以正常工作。
methods: {
add_friend(){
this.loading = true
this.$http.get('/add_friend/' + this.profile_user_id)
.then( (r) => {
if(r.body == 1)
this.status = 'waiting'
this.loading = false
})
你的if
状态错过了花括号。这仅适用于单行语句,但不适用于多行语句。
if(r.body == 1) {
this.status = 'waiting';
this.loading = false;
}
检查r.body
是否包含1
。
如果你从laravel控制器返回body
,那么你的http块在vue中应该如下所示:
this.$http.get('/add_friend/' + this.profile_user_id)
.then( (r) => { // you can also use destructing
const data = r.data;
if(data.body == 1)
this.status = 'waiting'
this.loading = false
})