代码之家  ›  专栏  ›  技术社区  ›  dede.brahma

VueJs-元素UI el select:如何获取值父级和子级

  •  0
  • dede.brahma  · 技术社区  · 6 年前

    我和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: ''
      }
    }
    

    预期:当有children和child为[]时,我希望选择选项,可以选择它。

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

    1 回复  |  直到 6 年前
        1
  •  1
  •   Regolith Luciens    3 年前

    有两种选择:

    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>