Vue equivalent of setTimeout?

前端 未结 13 2308
栀梦
栀梦 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:49

    vuejs 2

    first add this to methods

    methods:{
        sayHi: function () {
          var v = this;
          setTimeout(function () {
            v.message = "Hi Vue!";
        }, 3000);
       }
    

    after that call this method on mounted

    mounted () {
      this.sayHi()
    }
    

提交回复
热议问题