当我尝试添加朋友时,按钮正在加载并再次显示,而不是等待响应,但是刷新页面后它会起作用。
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
})
答案 0 :(得分:2)
您的if
条件缺少大括号。这仅对单行语句有效,而对多行无效。
if(r.body == 1) {
this.status = 'waiting';
this.loading = false;
}
还要检查r.body
是否包含1
。
答案 1 :(得分:0)
如果您要从laravel控制器返回body
,则vue中的http块应如下所示:
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
})