关于elementui 中select选中值绑定为对象时

来源:互联网 发布:淘宝如何打上新品标签 编辑:程序博客网 时间:2024/06/16 09:46

注:值为对象类型时,需要提供一个 value-key 作为唯一性标识

HTML:

<el-form-item v-if="item.type=='fncsel' && item.grid!='two'" :label="item.label" :class='{"is-required":item.required}'>

      <el-select class="fl" placeholder="请选择" value-key="name" v-model="item.value" @visible-change="fncselvchange(item)" @change="formChangeFun">
         <el-option v-for="option in item.options" :key="option.name" :value="option" :label="option.name"  :id="option.id"></el-option>
      </el-select>

      <i v-if="item.oper" class="fpselico" :class="item.oper.ico" :title="item.oper.name" @click="fpselBtnClick(item)"></i>

</el-form-item>


JS:

fncselvchange(item){
        var _this = this;
        var qs=require('qs');
        item.options=[];
        axios.post("/api/base/para/getParaListByCode", qs.stringify({
          code:item.code,
          token:this.$store.state.token.token
        })).then(function (response) {
          response.data.data.forEach((item1)=>{
            item.options.push({
              id:item1.id,
              valStr:item1.valStr,
              name:item1.name,
            });
          })
        })
   },
    fpselpchange(item){
        if(item.hasCasc==true){
          var _this = this;
          var qs=require('qs');
          item.options=[];
          axios.post("/api/base/para/getParaListByCode", qs.stringify({
            code:item.code,
            token:this.$store.state.token.token
          })).then(function (response) {
            response.data.data.forEach((item1)=>{
              item.options.push({
                id:item1.id,
                valStr:item1.valStr,
                name:item1.name,
                paraInfo:item1.paraList[0]
              });
            })
          })
        }
      },

阅读全文
0 0
原创粉丝点击