cube-ui icon indicating copy to clipboard operation
cube-ui copied to clipboard

Dialog Prompt组件问题

Open JennysGit opened this issue 7 years ago • 4 comments

使用 Dialog Prompt组件,关闭弹框时,input框的值没有清空,下次打开时,还是以前的值。

JennysGit avatar Mar 22 '19 09:03 JennysGit

因为 dialog 是单例模式的,当前组件周期内只存在一个,所以上次的会保留,可以修改 prompt.value 进行更新,就如同你在当前组件中在模板中写 Dialog 一样的效果。

dolymood avatar Mar 23 '19 02:03 dolymood

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?

zhangyuhuihh avatar Mar 28 '19 11:03 zhangyuhuihh

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() 解决了,每次都会重新获取数据。

heqiqi avatar Nov 20 '20 10:11 heqiqi

为什么可以使用onCancel,源码位置在哪,求告知

AI-fisher avatar Nov 26 '21 08:11 AI-fisher