• elementUI——select 根据传入的ID值选中选项


    问题:

      form表单配合select 没有选中传入相关信息的值,只显示传入的值

    原因:

      select选项的值与传入form表单的值的类型不一致,导致无法选中select中的选项

    示例:

      因为interfaceSharing 数据中的Value值为String类型而,form 中的Sharing原始类型为number类型,所以无法选中,这时只要把类型转换一下即可

    使用:this.form.Sharing = this.form.Sharing.toString();将number类型转换为String类型即可选中选项

    一下为无法选中示例

    // 省略无关内容
    // interfaceSharing 数据中的Value值为String类型
            <el-form-item label="是否允许" prop="Sharing">
              <el-select v-model="form.Sharing" placeholder="请选择" @change="selectChange">
                <el-option
                  v-for="item in interfaceSharing"
                  :key="item.Value"
                  :label="item.Label"
                  :value="item.Value"
                />
              </el-select>
            </el-form-item>
    //省略多行
        handleUpdate(row) {
          getInterface(id).then((response) => {
            this.form = response.data;
            console.log("获取的数据项类型");
            console.log(this.form.Sharing);
            console.log("this.form.Sharing类型:",typeof(this.form.Sharing));
          });
        },
        selectChange(value){
          console.log("修改的值");
          console.log(value);
          console.log("value类型:",typeof(value));
        },
    

      

    转换类型后选中选项

  • 相关阅读:
    Java 中几种常用的线程池
    阿里巴巴java工程师面试经验详情
    设计模式-备忘录模式
    设计模式-职责链模式
    设计模式-中介者模式
    设计模式-解释器模式
    设计模式-观察者模式
    设计模式-迭代器模式
    设计模式-命令模式
    设计模式-模板方法模式
  • 原文地址:https://www.cnblogs.com/lucky-jun/p/15266233.html
Copyright © 2020-2023  润新知