vue pass object to props code example

Example 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')
  }
}

Example 2: vue passing props

<!-- Dynamically assign the value of a variable -->
<blog-post v-bind:title="post.title"></blog-post>

<!-- Dynamically assign the value of a complex expression -->
<blog-post
  v-bind:title="post.title + ' by ' + post.author.name"
></blog-post>