<template>
<div>
<el-button @click="openMessageBox">打开MessageBox</el-button>
<el-button @click="updateMessageBoxContent">打开MessageBox</el-button>
</div>
</template>
<script>
import CustomInput from './CustomInputs';
export default {
data() {
return {
messageBoxContent: '初始内容',
password: '',
modifyFlag: false,
};
},
methods: {
openMessageBox() {
const h = this.$createElement;
this.$msgbox({
title: '消息',
message: h('div', null, [
h(CustomInput, {
key: new Date().getTime(),
props: { value: this.password, modifyFlag: this.modifyFlag },
on: {
input: (value) => {
this.password = value;
},
},
}),
]),
showCancelButton: true,
beforeClose: (action, instance, done) => {
console.log(instance, '.........');
console.log(instance.getMessage());
if (action === 'confirm') {
setTimeout(() => {
done()
setTimeout(() => {
instance.confirmButtonLoading = false
}, 300)
}, 3000)
// 在这里可以编写确认时的逻辑
} else {
done();
}
}
}).then(action => {
// 用户点击按钮后的回调
}).catch(err => {
console.log(err);
});
},
updateMessageBoxContent() {
this.messageBoxContent = '更新后的内容';
}
}
};
</script>