★ Vue中子组件调用父组件的方法总结
1、子组件中通过“ this.$parent.event ”来调用父组件的方法。
2、子组件用“$emit”向父组件触发一个事件,父组件监听这个事件即可。
3、父组件把方法传入子组件中,在子组件里直接调用这个方法即可。
Vue中子组件调用父组件的方法,这里有三种方法提供参考。
第一种方法是直接在子组件中通过this.$parent.event来调用父组件的方法。
父组件(Parent.vue):
<template>
<p>
<child></child>
</p>
</template>
<script>
import child from '~/components/dam/child';
export default {
components: {
child
},
methods: {
fatherMethod() {
console.log('测试');
}