0

I would like to call function b from inside function a in a vue.js component

This is the code I have

   methods:{
      a(){ 
            console.log("a")
            b();
       }
      b(){
           console.log("b")
       }
    }

2 Answers 2

1

you can do it by adding this before your function: this.yourFunction

export default{
    data(){
        return{
            data1: 1,
            data2: 1
        }
    },
    methods:{
        a(){
            if(this.data1 == this.data2){
                this.b(); //call b() function
            }
        },
        b(){
            //do something
        },
    }
}

you can also do the same to use your data() variables

Sign up to request clarification or add additional context in comments.

2 Comments

you can also do the same to use your data() variables --means? can u please provide eg
inside the if, I used data1 and data2
0

Use this it will solve the problem.

 methods:{
  a(){ 
        console.log("a")
        this.b();
   }
  b(){
       console.log("b")
   }
}

If you want to call it outside the method use this.method()

Documentation reference

2 Comments

i just meant outside methods not outside the export or vue :)
ya u can doesnt matter if not marked just keeping posting it will help some or the other:)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.