dialogVisible父组件提供,:visible.sync直接修改父组件的dialogVisible,会报错,需要加上before-close属性
<template> <el-dialog title="提示" :visible.sync="dialogVisible" width="30%" :before-close="handleClose"> <span>这是一段信息</span> <span slot="footer" class="dialog-footer"> <el-button @click="handleCancel">取 消</el-button> <el-button type="primary" @click="handle">确 定</el-button> </span> </el-dialog> </template> <script> export default { name: "InfoIndexDialog", props: { dialogVisible: { type: Boolean, required: true } }, data() { return {}; }, methods: { changePropsDialogVisible() { this.$emit("update:dialogVisible", false); }, handleClose() { this.changePropsDialogVisible(); }, handleCancel() { this.changePropsDialogVisible(); }, handle() { this.changePropsDialogVisible(); } } }; </script> <style lang="scss" scoped> </style>