About the element UI drop-down option select binding value cannot be translated and echoed

When doing the pull-down echo of the select component, some of the option id values ​​returned by the background are string types: id: '1', while elementUI has made a strict judgment that the type must be number type.
Especially multi-select:

<template>
  <div>
    <el-select v-model="aaa" placeholder="请选择" multiple >
      <el-option
        v-for="item in options"
        :key="item.value"
        :label="item.label"
        :value="item.value"
      >
      </el-option>
    </el-select>
    <el-button @click="submitStr" type="primary">提交</el-button>
  </div>
</template>

<script>
export default {
    
    
  name: 'WorkspaceJsonChild3',

  data() {
    
    
    return {
    
    
      options: [{
    
    
        value: 1,
        label: '黄金糕'
      }, {
    
    
        value: 2,
        label: '双皮奶'
      }, {
    
    
        value: 3,
        label: '蚵仔煎'
      }, {
    
    
        value: 4,
        label: '龙须面'
      }, {
    
    
        value: 5,
        label: '北京烤鸭'
      }],
      aaa: []
    };
  },

  mounted() {
    
    
    this.getRow()
  },

  methods: {
    
    
    // 从后台获取数据回显时要把字符串转为number类型数组,
   getRow(){
    
    
     setTimeout(() => {
    
    
       let strList = '1,5'
       this.aaa = strList.split(',').map(Number)
       
     }, 1000);
   },
  //  回显完提交给后台的数据是逗号分割的字符串
   submitStr(){
    
    
     console.log(this.aaa)
     const bbb = this.aaa.join(',')
     console.log(bbb)
   }
  }
}
</script>

<style lang="scss" scoped>
</style>

Guess you like

Origin blog.csdn.net/weixin_43045869/article/details/127930850