el-select 进行分组,同时可以多层选择

<!-- eslint-disable vue/no-mutating-props -->
<template>
  <div class="step-one-form" v-show="currentStep === 2">
    <el-select v-model="selected">
      <el-option-group v-for="group in options" :key="group.label" :label="group.label">
        <template v-if="group.children">
          <el-option-group
            v-for="subGroup in group.children"
            :key="subGroup.label"
            :label="subGroup.label"
            style="margin-left: 10px; color: red"
          >
            <el-option
              v-for="item in subGroup.options"
              :key="item.value"
              :label="item.label"
              :value="item.value"
              style="margin-left: 10px"
            />
          </el-option-group>
        </template>
        <el-option
          v-else
          v-for="item in group.options"
          :key="item.value"
          :label="item.label"
          :value="item.value"
          style="margin-left: 10px"
        />
      </el-option-group>
    </el-select>
  </div>
</template>

<script setup lang="ts">
const props = defineProps({
  currentStep: {
    type: Number,
    default: 1
  }
})

const options = ref<any>([
  {
    label: "必须 *",
    id: 1,
    children: [
      {
        value: "lianxifangshi",
        label: "联系方式",
        isMore: true,
        options: [
          {
            value: "Shanghai",
            label: "邮箱"
          },
          {
            value: "Beijing",
            label: "电话"
          }
        ]
      },
      {
        value: "lianxiren",
        label: "联系人"
      }
    ]
  },
  {
    label: "非必选",
    id: 2,
    options: [
      {
        value: "Chengdu",
        label: "成都"
      },
      {
        value: "Shenzhen",
        label: "深圳"
      },
      {
        value: "Guangzhou",
        label: "广州"
      },
      {
        value: "Dalian",
        label: "大连"
      }
    ]
  }
])
const selected = ref<any>([])
</script>

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

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值