Vue:methods方法调用方法 (踩坑随记)

版权声明:转载请标明出处。 https://blog.csdn.net/qq_42172829/article/details/83686578

Vue:methods函数集中不能像原声JS中直接调用函数,踩坑半天差点爬不起。

1.首先在methods中定义一个函数,

redierct(){
    window.location.href="https://www.baidu.com/?tn=98012088_5_dg&ch=12"
}

2.在methods其中一个方法中调用

this.$options.methods.redierct()

上述只是一个简单跳转做个例子,方法中具体操作看个人使用场景。

不过好像也可以使用 ↓  ,自己试了一下也能被调用到,不过不推荐

var that = this;
that.方法名();

猜你喜欢

转载自blog.csdn.net/qq_42172829/article/details/83686578