$emit 子传参给父
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了$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 子传参给父的主要内容,如果未能解决你的问题,请参考以下文章