外部js调用vue实例方法

  |   0 评论   |   0 浏览

vue函数

mounted () {
      window.testFun = this.testFun;    // 方法赋值给window
 },
 methods: {
 	// vue内部方法
	testFun () {

	},
 }

外部js调用

<script>

    function test() {
      testFun();   // 直接通过window方法去调用methods中对应方法
    }

</script>