vue之 methods的方法的相互调用

vue在同一个组件内;方法之间经常需要互相调用。

methods中的一个方法如何调用methods中的另外一个方法呢?

可以在调用的时候使用  this.$options.methods.test2();

new Vue({

     el: '#app',

     data: {

         test:111,

     },

     methods: {

          test1:function(){

              alert(this.test)

         },

         test2:function(){

             alert("this is test2")

             alert(this.test) //test3调用时弹出undefined

        },

        test3:function(){

                this.$options.methods.test2();//在test3中调用test2的方法

        }

    }

})

微信公号搜索:李大头头。(或扫描二维码)找我来玩。

更多【前端技术群】和【内推职位】 资源等着你。

还不定期在公众号请大家喝奶茶!

想与我聊聊或者有什么问题都可以在公众号找到我。

等你哟~

猜你喜欢

转载自blog.csdn.net/ljy_1024/article/details/89968000