vue 子组件向父组件传值

Posted MrWang

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了vue 子组件向父组件传值相关的知识,希望对你有一定的参考价值。

父组件这么写
<component-a  v-on:child-say="listenToMyBoy"></component-a>

<p>Do you like me? {{childWords}}</p>

 methods: {

            listenToMyBoy: function (somedata){

              this.childWords = somedata

            }

        }

 

子组件component-a这么写

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

 

methods: {

      onClickMe: function(){

        this.$emit(child-say,this.somedata);

      }

 

以上是关于vue 子组件向父组件传值的主要内容,如果未能解决你的问题,请参考以下文章

vue子组件向父组件传值

vue 子组件向父组件传值方法

Vue_(组件通讯)子组件向父组件传值

子组件向父组件传值

vue子组件向父组件传值

Vue 组件&组件之间的通信 之 子组件向父组件传值