在不更新Vue的情况下更新页面上的数据?

时间:2018-12-08 12:02:16

标签: laravel vue.js

当我尝试添加朋友时,按钮正在加载并再次显示,而不是等待响应,但是刷新页面后它会起作用。

   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

                })

2 个答案:

答案 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

            })
相关问题