el-select multiple 数据回显问题

v-model接收的数据应该是数组,而已数组里的参数必须是number:[0, 1 , 2] 的形式,才能正确显示。

<el-select v-model="edtBox.term_with" :multiple-limit="2" multiple placeholder="请选择" @change="organsChange">
  <el-option
    v-for="item in organs"
    :key="item.term_id"
    :label="item.term_name"
    :value="item.term_id"
  />
</el-select>

后端返回回来的是字符串所以对数据进行重构,先酱字符串转换为数组,再去遍历,将item的值转换为number,最后重新push。

lookDetail(row) {
  if (row.term_with) {
    const arr = row.term_with.split(',')
    const list = []
    arr.map(item => {
      list.push(parseInt(item))
    })
    this.edtBox.term_with = list
  } else {
    this.edtBox.term_with = ''
  }
}
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容