Vue equivalent of setTimeout?

前端 未结 13 2314
栀梦
栀梦 2021-01-30 08:20

I\'m making a shopping cart system with Laravel and Vue. When I add an item to the basket, I display a confirmation message by toggling a Vue variable being watched by a v-if:

13条回答
  •  野的像风
    2021-01-30 08:35

    It is likely a scope issue. Try the following instead:

    addToBasket: function(){
        item = this.photo;
        this.$http.post('/api/buy/addToBasket', item);
        this.basketAddSuccess = true;
        var self = this;
        setTimeout(function(){
            self.basketAddSuccess = false;
        }, 2000);
    }
    

提交回复
热议问题