常见问题:vue+element项目el-dialog弹窗提交数据,表格需要手动刷新才能出现数据怎么解决?
这个时候就需要用到el-dialog子组件调用父组件表格的方法。
vue子组件怎么调用父组件的方法?一招搞定先看下面demo。
父组件
<template>
<p>
<child @fatherMethod="fatherMethod"></child>
</p>
</template>
<script>
import child from '~/components/dam/child';
export default {
components: {
child
},
methods: {
fatherMethod() {
console.log('测试');
}
}
};
</script>
子组件
<template>
<p>
<button @click="childMethod()">点击</button>
</p>
</template>
<script>
export default {
methods: {
childMethod() {
this.$emit('fatherMethod');
}
}
};
</script>
那么结合具体项目
父组件
子组件