子組件
<template>
<div>
<button @click="childEvent()">點擊調(diào)父組件方法</button>
</div>
</template>
<script>
export default {
methods: {
childEvent() {
this.$emit('parent-event');
}
}
};
</script>
子組件發(fā)出
this.$emit('parent-event');
$emit: 發(fā)出
parent-event : 方法
父組件
<template>
<div>
<child @parent-event="parentEvent"></child>
</div>
</template>
<script>
import child from './child';
export default {
components: {
child
},
methods: {
parentEvent() {
console.log('我是父類方法');
}
}
};
</script>
父組件接收
<child @parent-event="parentEvent"></child>
@parent-event : 接收