$emit 子傳參給父
阿新 • • 發佈:2017-07-15
ren turn v-on something som msg rom mouse emit
parent.vue
<template> <div class="wapper"> <p>child tells me:{{childWord}}</p> <child v-on:child-tell-me-something="listenToMyBoy"></child> </div> </template> <script> import child from ‘../components/child‘ export default { name:‘wapper‘, components:{child}, data(){return{ childWord:‘‘ } }, methods:{ listenToMyBoy(msg){ this.childWord=msg } } } </script>
child.vue
<template> <div> <div @click="up">點我open mouse! </div> </div> </template> <script> exportdefault{ data(){ return { msg: ‘hello from components a‘ } }, methods: { up() { this.$emit(‘child-tell-me-something‘,this.msg) } } } </script>
$emit 子傳參給父