Home >Web Front-end >JS Tutorial >How to pass value from child component to parent component in vue

How to pass value from child component to parent component in vue

亚连
亚连Original
2018-06-04 14:11:293118browse

Below I will share with you a method of passing values ​​from a vue sub-component to a parent component. It has a good reference value and I hope it will be helpful to everyone.

The child component registers to trigger the event, and the method after the parent component registers to trigger the child component event is written in the method

The parent component writes like this

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

The sub-component component-a is written like this

<button v-on:click="onClickMe">like!</button>
methods: {
  onClickMe: function(){
  this.$emit(&#39;child-say&#39;,this.somedata);
  }
 }

The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.

Related articles:

By using ueditor in the vue project (detailed tutorial)

By introducing noVNC remote desktop in the vue project What are the method steps

How to use nodejs crawler to use superagent and cheerio

The above is the detailed content of How to pass value from child component to parent component in vue. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn