Vue 子組件向父組件傳值

這裏的child-say 是指定的不能更改this

父組件code

<component-a  v-on:child-say="listenToMyBoy"></component-a>
<p>Do you like me? {{childWords}}</p>
 methods: {
            listenToMyBoy: function (somedata){
              this.childWords = somedata
            }
        }

 

子組件component

<button v-on:click="onClickMe">like!</button>

methods: {
      onClickMe: function(){
        this.$emit('child-say',this.somedata);
      }
    }
相關文章
相關標籤/搜索