【问题标题】:VueJs - Element UI el-select: How to get value parent and childVueJs - Element UI el-select:如何获取价值父母和孩子
【发布时间】:2018-05-25 04:06:39
【问题描述】:

我有 el-select-group 的案例 当我使用 el-select-group 和数据时,孩子是 [],无法选择选项 这是我的数据

data() {
  return {
    options3: [{
      label: 'Popular cities',
      options: [{
        value: 'Shanghai',
        label: 'Shanghai'
      }, {
        value: 'Beijing',
        label: 'Beijing'
      }]
    }, {
      label: 'Indonesia',
      options: [{
        value: 'Jakarta',
        label: 'Jakarta'
      }, {
        value: 'Bandung',
        label: 'Bandung'
      }]
    }, {
      label: 'Singapore',
      options: []
    }, {
      label: 'Thailand',
      options: []
    }],
    value7: ''
  }
}

预期:当它有孩子时我想要选择的选项,当孩子是[]时,它可以被选中。

这是我的代码 https://jsfiddle.net/dede402/jruzj07d/

【问题讨论】:

  • 你的问题不清楚,请解释清楚。

标签: vuejs2 selection element-ui


【解决方案1】:

有两种选择:

  1. 为您的数据添加选项

    {
      label: 'Singapore',
      options: [{
      value: 'Singapore',
      label: 'Singapore'
     }]
    }
    
  2. 更改模板:

    <template>
      <el-select v-model="value7" placeholder="Select">
        <template v-for="group in options3">
           <el-option-group v-if="group.options.length > 0" :key="group.label" :label="group.label">
          <el-option v-for="item in group.options" :key="item.value" :label="item.label" :value="item.value">
          </el-option>
        </el-option-group>
          <el-option v-else :key="group.label" :label="group.label" :value="group.label">
          </el-option>
       </template>
      </el-select>
    </template>

【讨论】:

  • 它运行了,谢谢。但是如果没有孩子的父母和没有孩子的父母之间没有分隔符列表
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-11-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-08-30
  • 2018-05-19
  • 2018-01-29
相关资源
最近更新 更多