关于在.js里面调用Element UI 的自定义MessageBox 弹框无法获取输入值的问题,以下是获取输入值的方法:

     x.onClick = (async () => {
                this.$msgbox({
                  title: '提示',
                  message:
                    h('div', null, [
                      h('div', null, '请输入账户密码:'),
                      h('input', {
                        type: 'password',
                        id: "pwdInput",
                      }),
                      h('div', null, '请输入作废原因:'),
                      h('textarea', {
                        id: "remarksInput",
                      }),
                    ]),
                  showCancelButton: true,
                  confirmButtonText: '确定',
                  cancelButtonText: '取消',
                  beforeClose: (action, instance, done) => {
                    if (action === 'confirm') {
                      // 通过ID获取输入框元素  
                      const inputElementPwd = document.getElementById('pwdInput');
                      // 获取输入框的值  
                      const inputValuePwd = inputElementPwd.value;
                      const inputElementRemarks = document.getElementById('remarksInput');
                      // 获取输入框的值  
                      const inputValueRemarks = inputElementRemarks.value;
                      if (inputValuePwd == "") {
                        ElMessage.error("请输入密码!");
                        return;
                      }
                      if (inputValueRemarks == "") {
                        ElMessage.error("请输入作废原因!");
                        return;
                      }
                      instance.confirmButtonLoading = true
                      instance.confirmButtonText = '执行中...'
                      setTimeout(() => {
                        done();
                        setTimeout(async () => {
                          let params = {
                            delKeys: null,
                            detailData: [],
                            mainData: {
                              WKInfo_Id: row.WKInfo_Id,
                              IsEnable: "1",
                              pwd: inputValuePwd, // 使用获取的密码值  
                              Remark: inputValueRemarks, // 使用获取的备注值   
                            }
                          }
                          let res = await http.post("/api/WorkReportInfo/Update", params);
                          if (res.status) {
                            ElMessage.success("作废成功!");
                            row.IsEnable = 1;
                            this.onModelClose();
                          }
                          else {
                            ElMessage.error("作废失败!" + res.message);
                          }
                          instance.confirmButtonLoading = false
                        }, 300)
                      }, 3000)
                    } else {
                      done()
                    }
                  },
                }).then((action) => {
                  this.$message({
                    type: 'info',
                    message: 'action: ' + action,
                  })
                });
              })

使用id进行值的获取 :  document.getElementById('xxx').value

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值