cube-ui
cube-ui copied to clipboard
Dialog Prompt组件问题
使用 Dialog Prompt组件,关闭弹框时,input框的值没有清空,下次打开时,还是以前的值。
因为 dialog 是单例模式的,当前组件周期内只存在一个,所以上次的会保留,可以修改 prompt.value 进行更新,就如同你在当前组件中在模板中写 Dialog 一样的效果。
editPhone(index) {
this.$createDialog({
type: 'prompt',
title: '修改预留手机号',
prompt: {
value: '',
placeholder: '请输入'
},
confirmBtn: {
text: '确定',
active: true,
disabled: false,
href: 'javascript:;'
},
cancelBtn: {
text: '取消',
active: false,
disabled: false,
href: 'javascript:;'
},
onConfirm: (e, promptValue) => {
if ((!/^((13[0-9])|(14[5,7])|(15[0-3,5-9])|(17[0,3,5-8])|(18[0-9])|166|198|199|(147))\d{8}$/.test(promptValue) && promptValue !== '')) {
this.$createToast({
type: 'warn',
time: 1000,
txt: `格式错误,请重新编辑`
}).show()
} else if (promptValue === '') {
this.$createToast({
type: 'warn',
time: 1000,
txt: `未作出修改`
}).show()
} else {
this.merchartList[index].phone = promptValue
this.$createToast({
type: 'correct',
time: 1000,
txt: `修改成功`
}).show()
}
},
onCancel: (e) => {
// this.prompt.value = ''
this.$createToast({
type: 'warn',
time: 1000,
txt: '已取消'
}).show()
}
}).show()
},
这里面怎么才能拿到prompt.value?
editPhone(index) { this.$createDialog({ type: 'prompt', title: '修改预留手机号', prompt: { value: '', placeholder: '请输入' }, confirmBtn: { text: '确定', active: true, disabled: false, href: 'javascript:;' }, cancelBtn: { text: '取消', active: false, disabled: false, href: 'javascript:;' }, onConfirm: (e, promptValue) => { if ((!/^((13[0-9])|(14[5,7])|(15[0-3,5-9])|(17[0,3,5-8])|(18[0-9])|166|198|199|(147))\d{8}$/.test(promptValue) && promptValue !== '')) { this.$createToast({ type: 'warn', time: 1000, txt: `格式错误,请重新编辑` }).show() } else if (promptValue === '') { this.$createToast({ type: 'warn', time: 1000, txt: `未作出修改` }).show() } else { this.merchartList[index].phone = promptValue this.$createToast({ type: 'correct', time: 1000, txt: `修改成功` }).show() } }, onCancel: (e) => { // this.prompt.value = '' this.$createToast({ type: 'warn', time: 1000, txt: '已取消' }).show() } }).show() },这里面怎么才能拿到prompt.value?
兄弟,我用的 dialog.remove() 解决了,每次都会重新获取数据。
为什么可以使用onCancel,源码位置在哪,求告知