学无先后,达者为师

网站首页 编程语言 正文

Element-UI中selet下拉框无法回显问题

作者:weixin_42180332 更新时间: 2022-06-08 编程语言

使用elementUI时,在修改页面,下拉框回显数据有问题

这里客户ID需要默认选中id为8的客户。并且显示客户名称 

<el-form-item label="客户" prop="customerId">
        <el-select v-model="form.customerId" placeholder="请选择">
          <el-option 
             v-for="item in customerList" 
             :value="item.customerId"             
            :label="item.customerName">
          </el-option>
        </el-select>
 </el-form-item>

原因:<el-option>中 :value的值与<el-select>的 v-model值不匹配,我这里form.customerId的值为字符串,而item.customerId的值为数字类型,所以导致回显数据无法自动选中

解决:将form.customerId和item.customerId转换为同一类型 ,并检查数据是否相同

 

原文链接:https://blog.csdn.net/weixin_42180332/article/details/106944853

栏目分类
最近更新