How to call a method in vue app from the vue component

后端 未结 2 2149
生来不讨喜
生来不讨喜 2021-02-20 18:58

I have a vue component and a vue element declaration as given below

Vue.component(\'todo-item\', {
  template: \'
  • This is a todo
  • \' methods:
    2条回答
    •  一整个雨季
      2021-02-20 19:13

      You can execute root instance method like this: this.$root.methodName()

        Vue.component('todo-item', {
            template: '
    • This is a todo
    • ', methods: { test: function() { this.$root.aNewFunction(); } }, mounted() { this.test(); } }) new Vue({ el: '#app', template: '', methods: { aNewFunction: function() { alert("inside"); } } })

    提交回复
    热议问题