第一步:
在父组件中在父组件引入子组件、注册、使用、绑定自定义函数
//引入子组件
import InforList from "../view/InforList/index.vue";
//注册
components: {
InforList,
},
<!-- 使用和绑定自定义函数 -->
<InforList @func="getMsg"></InforList>
第二步:
在子组件中触发
<template>
<div>
<el-badge :value="xc" class="item">
<i class="el-icon-bell"></i>
</el-badge>
<el-button type="primary" @click="SonDad">子传父</el-button>
</div>
</template>
<script>
export default {
props: {
xc: Number,
},
data() {
return {
msg: "我是子组件的值",
};
},
methods: {
SonDad() {
this.$emit("func", this.msg);
//func代表父组件自定义的函数,msg是要传给父组件的值
},
},
};
</script>