父组件
<template>
<div>
<TestCd :text="text" @textFun="textFun"></TestCd>
</div>
</template>
<script>
//引入子组件
import TestCd from "./testcd.vue"
export default {
data() {
return {
text: "父组件的数据",
};
},
components:{
TestCd
},
methods: {
textFun(obj) {
console.log('父组件的方法',obj);
},
},
};
</script>
<style>
</style>
子组件
<template>
<div @click="change">
{{text}}
</div>
</template>
<script>
export default {
props:{
text:String
},
methods:{
change(){
let obj={
a:1,
b:2
}
//第一个参是父组件的方法,第二个是需要传到父组件的数据
this.$emit('textFun',obj)
}
}
}
</script>
<style>
</style>