vue 如何在子组件中调用父组件的方法???
子组件如何调用父组件方法?
1 在父组件中: 通过注册标签 @绑定好方法
2 子组件中:通过this.$emit来调用
如下。。。。
父组件
<template>
<div>
<child @fatherMethod="fatherMethod"></child>
</div>
</template>
<script>
import child from '~/components/dam/child';
export default {
components: {
child
},
methods: {
fatherMethod() {
console.log('这是父组件中的方法');
}
}
};
</script>
子组件
<template>
<div>
<button @click="childMethod()">点击</button>
</div>
</template>
<script>
export default {
methods: {
childMethod() {
this.$emit('fatherMethod'); //调用父组件中的方法
}
}
};
</script>

浙公网安备 33010602011771号