[Vuejs]-Vue: Access component object inside methods

4👍

According to official docs You should use normal function instead of arrow one in order to get access to the component instance :

    methods: {
      getInput() {
        return this.$ref.input.value 
      }
    }

Note that you should not use an arrow function to define a method (e.g. plus: () => this.a++). The reason is arrow functions bind the parent context, so this will not be the Vue instance as you expect and this.a will be undefined.

Leave a comment