elementui中的el-input回显成功后input框不能进行编辑的问题

通过接口拿到数据后,input框无法进行编辑
在这里插入图片描述

    <el-dialog v-dialogDrag title="RPA" :visible.sync="accountVisible" width="30%">
      <el-form ref="accountForm" :model="accountForm" :rules="rules" label-width="200px">
        <el-form-item label="Channel" prop="channel" placeholder="Bkash">
          <el-input v-model="accountForm.channel" clearable></el-input>
        </el-form-item>
        <el-form-item label="Company Name" prop="companyName">
          <el-input v-model="accountForm.companyName" clearable></el-input>
        </el-form-item>
        <el-form-item label="Account No." prop="accountNo">
          <el-input v-model="accountForm.accountNo" clearable></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="accountVisible = false">Cancel</el-button>
        <el-button type="primary" @click="saveaAccountEdit">Confirm</el-button>
      </span>
    </el-dialog>
    getAccountInfo() {
      this.queryProperties.appCode = this.appCode
      this.queryProperties.propertiesList = 'channel,companyName,accountNo'
      crud.findProperties(app_url, this.queryProperties).then((res) => {
        if (res.code == 0) {
          if (res.data != null) {
            this.accountForm.channel = res.data.channel
            this.accountForm.companyName = res.data.companyName
            this.accountForm.accountNo = res.data.accountNo
          }
          this.accountVisible = true
        } else {
          this.$message({
            message: res.msg,
            type: 'error',
            duration: 2000,
          })
        }
      })
    },

原因:

在Vue实例创建时,obj.b并未声明,因此就没有被Vue转换为响应式的属性,自然就不会触发视图的更新。

解决办法:

这时就需要使用Vue的全局api $set():
$set()方法相当于手动的去把obj.b处理成一个响应式的属性,此时视图也会跟着改变了
在这里插入图片描述
这样子就可以了。
遇到同样问题的小伙伴,可以试一下,具体原理搞不明白不重要,试一下就知道了,结果会让你吃惊的。

  • 3
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值