子组件:
<template>
<button @click="clickme">点击我</button>
</template>
<script>
export default {
data() {
return {
message: "我是要传递的数据"
}
},
methods: {
clickme(){
this.$emit('my-click', this.message)
}
}
}
</script>
父组件:
<template>
<div id="app">
<child-a @my-click="getMessage"></child-a>
<!--父组件中通过监测my-event事件执行一个方法,然后取到子组件中传递过来的值-->
</div>
</template>
<script>
import sonfrom './components/son.vue'
export default {
components: {
son
},
methods: {
getMessage(msg){
console.log(msg)
}
}
}
</script>