实现方式
//vModelDialog.js
export default {
model: {
prop: 'visible',
event: 'change'
},
props: {
visible: {
type: Boolean,
default: () => {
return false;
}
}
},
computed: {
innerVisible: {
get: function () {
return this.visible;
},
set: function (val) {
this.$emit('change', val);
}
}
},
methods: {
handleDialogClose() {
this.$emit('change', false);
}
}
};
<!-- DetailDialog.vue -->
<template>
<el-dialog title="标题" :visible.sync="innerVisible" >
<div>弹窗内容</div>
</el-dialog>
</template>
import vModemodelDialoglDialog from './vModelDialog.js'
export default {
mixins: [vModelDialog],
}
使用:
<DetailDialog v-model="detailVisible" />