更新页面上的数据而不用Vue刷新?

问题描述 投票:0回答:2

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

   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

                })
laravel vue.js
2个回答
2
投票

你的if状态错过了花括号。这仅适用于单行语句,但不适用于多行语句。

if(r.body == 1) {
    this.status = 'waiting';
    this.loading = false;
}

检查r.body是否包含1


0
投票

如果你从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

            })
© www.soinside.com 2019 - 2024. All rights reserved.