Vue 子组件中触发父组件方法

父组件中:

<子组件名 @close="close"></子组件名>
methods: {
    close(id) {
        this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
        }).then(() => {
            this.$message({
                type: 'success',
                message: '删除成功!'
            });
        }).catch(() => {
            this.$message({
                type: 'info',
                message: '已取消删除'
            });
        });
    }

子组件中:

<el-button size="mini" type="primary" @click="close('5')">关闭</el-button>
methods: {
close(id){
    this.$emit('close',id);
    console.log(id);
}
}子组件中通过this.$emit()触发父组件中方法

猜你喜欢

转载自blog.csdn.net/qq_40851816/article/details/79928069