报错信息:Avoid mutating a prop directly since the value will be overwritten whenever the parent component re-renders. Instead, use a data or computed property based on the prop’s value. Prop being mutated: “dialogVisible”。
出现此报错情景:关闭弹出的窗口时
错误原因:如果要使用 :visible.sync 修饰符,:visible.sync的值必须等于当前组件的data里定义的值或者计算属性里的值,props里的值则会报上图的错误。
父组件:
data(){
diaVisible: false, // 弹窗的显示
}
子组件:
props: {
dialogVisible: {
type: Boolean,
default: true
}
<el-dialog
:visible.sync="dialogVisible"
title="新增部门"
width="42%"
/>
解决方案:
<el-dialog
:visible="dialogVisible"
title="新增部门"
width="42%"
/>