子组件
<template>
<div>
子组件:
<span>{{childValue}}</span>
<input type="button" value="点击触发" @click="childClick">
</div>
</template>
<script>
export default {
data () {
return {
childValue: '我是子组件的数据'
}
},
methods: {
childClick () {
this.$emit('childByValue', this.childValue)
}
}
}
</script>
父组件
<template>
<div>
父组件:
<span>{{name}}</span>
<br>
<br>
<child v-on:childByValue="childByValue"></child>
</div>
</template>
<script>
import child from './child'
export default {
components: {
child
},
data () {
return {
name: ''
}
},
methods: {
childByValue: function (childValue) {
this.name = childValue
}
}
}
</script>