elemnet-plus el-cascader数据回显

<template>
  <div>
    <el-cascader
      :options="data.allList"
      :show-all-levels="false"
      v-model="form.ids"
      :props="{ checkStrictly: true }"
    />
  </div>
</template>

<script setup>
import { ref, reactive, onMounted } from 'vue';
import { getCategoryList } from '@/api/category'; // 假设这是你的API请求

const data = reactive({
  allList: []
});

const form = reactive({
  ids: [] // 用于回显的值
});

onMounted(() => {
  getCategoryList().then(res => {
    if (res.code === 200) {
      data.allList = res.data;
      
      // 假设你要回显的值是 [3, 6],即一级分类下的二级分类00
      form.ids = [3, 6];
    }
  });
});
</script>

json

{
  "msg": "操作成功",
  "code": 200,
  "data": [
    {
      "id": 3,
      "name": "一级分类",
      "children": [
        {
          "id": 6,
          "name": "二级分类00"
        },
        {
          "id": 9,
          "name": "二级分类11"
        }
      ]
    },
    {
      "id": 8,
      "name": "一级分类1",
      "children": []
    },
    {
      "id": 2,
      "name": "测试1",
      "children": [
        {
          "id": 7,
          "name": "分类001"
        }
      ]
    }
  ]
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值