[Vuejs]-Function not defined error when calling from another function

3👍

Your approach is trying to execute a function from the window object or from whatever context was declared that object methods.

You need to call that function as follow:

this.selecteStep(1);

Further, you need to separate those methods/functions using comma ,

const methods = {
  selectStep: function (id) {
    console.log('called!', id);
  },
  controlStep: function () {
    this.selectStep(1);
  }
}

methods.controlStep();

2👍

You have to use this.anotherMethodName

<template>
    ...

    <button @click="callMethod"></button>

    ...
</template>

<script>
    export default {
        methods: {
            firstMethod() {
                console.log('called')
            },
            callMethod() {
                this.firstMethod()
            }
        }
    }
</script>

Leave a comment