子组件:
<template>
<div>
<el-input v-model="input" placeholder="请输入内容" @keyup.enter.native="sendMsg"/>
</div>
</template>
<script >
export default {
name: 'Child',
data() {
return {
input: '子组件的msg'
}
},
methods: {
sendMsg() {
this.$emit('send', this.input)
}
}
}
</script >
<style scoped >
</style >
父组件:
<template >
<div>
<v-child @send="getMsg"/>
</div>
</template >
<script >
import child from './child'
export default {
name: 'Parent',
components: { 'v-child': child },
data() {
return {}
},
methods: {
getMsg(data) {
console.log(data)
}
}
}
</script >
<style scoped >
</style >