console
Vue.component('welcome-button', {
template: `
<button v-on:click="$emit('welcome')">
Click me to be welcomed
</button>
`
})
var vm1 = new Vue({
el: '#emit-example-simple',
methods: {
sayHi: function () {
console.log('Hi!')
}
}
})
Vue.component('magic-eight-ball',{
data: function () {
return {
possibleAdvice: ['yes','no','maybe']
}
},
methods: {
giveAdvice: function () {
var randomAdviceIndex = Math.floor(Math.random()*this.possibleAdvice.length)
this.$emit('give-advice',this.possibleAdvice[randomAdviceIndex])
}
},
template: `
<button @click="giveAdvice">
Click me for advice
</button>
`
})
var vm2 = new Vue({
el:"#emit-example-argument",
methods: {
showAdvice: function (advice) {
console.log(advice)
}
}
})
<div id="emit-example-simple">
<welcome-button v-on:welcome="sayHi"></welcome-button>
</div>
<div id="emit-example-argument">
<magic-eight-ball v-on:give-advice="showAdvice"></magic-eight-ball>
</div>