1. 程式人生 > >vue中methods互相呼叫的方法

vue中methods互相呼叫的方法

a:function(goods) {
      this.aa= [];
      this.bb= 0;
      this.cc= 0;
    },
b:function(){
      if(this.bbb!= 0){
        this.aa= [];
        this.bb= 0;
        this.cc= 0;
        this.$message({
          message:'結賬成功!',
          type:'success'
        })
      }
    }

  上面程式碼塊裡a方法裡的程式碼和b方法裡面的程式碼一模一樣,可以使用

this.$options.methods.a.bind(this)();

  來替換

b:function(){
      if(this.bbb!= 0){
        this.$options.methods.a.bind(this)();
        this.$message({
          message:'結賬成功!',
          type:'success'
        })
      }
    }