1. 程式人生 > >$emit 子傳參給父

$emit 子傳參給父

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>
  export 
default{ data(){ return { msg: hello from components a } }, methods: { up() { this.$emit(child-tell-me-something,this.msg) } } } </script>

$emit 子傳參給父