Answers for "pass method as props vue"

Go
1

pass method as props vue

//You should probably not pass methods as props in Vue, instead, emit an event.

//In parent component, do for example:

<Child-Component @alert="sayHi" />

methods: {
  sayHi() {
	alert('Hi')
  }
}

// In child component, do:

<element @click="doSomething">

methods: {
  doSomething() {
  	this.$emit('alert')
  }
}
Posted by: Guest on October-25-2020

Browse Popular Code Answers by Language