Skip to content
官方QQ交流群
pc端ui:468705115   点此加入
移动端ui:468217742   点此加入
技术交流1:87208295   点此加入
技术交流2:787747122   点此加入
官网
云控制台
开放平台
关注微信公众号
代码仓库: 码云

cv-select-tree 树形选择器

简要

树形列表选择
单列树形列表选择,一般和表单配合使用,默认为实心白色背景。

示例

::: demo

vue
<template>
  <div style="width: 520px">
    <div style="display: flex; flex-direction: column; gap: 10px; margin-bottom: 10px">
      <cvSelectTree v-model="dlgData.pid" placeholder="123" :dataLists="treeOptions" :dataField="optionProps" />
    </div>
    <cv-btn-base @click="handleDataLists()">handleDataLists</cv-btn-base>
    <cv-btn-base @click="handleValue()">console.log</cv-btn-base>
    <!-- 显示数据 -->
    <pre style="margin-top: 20px; background: #f6f6f6; padding: 20px">{{ dlgData }}</pre>
  </div>
</template>
<script>
export default {
  data() {
    return {
      dlgData: {
        pid: ''
      },
      treeOptions: [
        {
          id: 'fruits',
          label: 'Fruits',
          tree: [
            { id: 'apple', label: 'Apple 🍎', isNew: true, disabled: true },
            { id: 'grapes', label: 'Grapes 🍇' },
            { id: 'pear', label: 'Pear 🍐' },
            { id: 'strawberry', label: 'Strawberry 🍓' },
            { id: 'watermelon', label: 'Watermelon 🍉' }
          ]
        },
        {
          id: 'vegetables',
          label: 'Vegetables',
          tree: [
            { id: 'corn', label: 'Corn 🌽' },
            { id: 'carrot', label: 'Carrot 🥕' },
            { id: 'eggplant', label: 'Eggplant 🍆' },
            { id: 'tomato', label: 'Tomato 🍅' }
          ]
        }
      ],
      optionProps: {
        value: 'id', // ID字段名
        label: 'label', // 显示名称
        children: 'tree' //
      }
    };
  },
  created() {
    setTimeout(() => {
      this.dlgData.pid = 'grapes';
    }, 1000);
  },
  methods: {
    handleDataLists() {
      this.treeOptions = [
        {
          id: 'fruits',
          label: 'Fruits',
          children: [
            { id: '1', label: '🍎', isNew: true },
            { id: '2', label: '🍇' },
            { id: '3', label: '🍐' },
            { id: '4', label: '🍓' },
            { id: '5', label: '🍉' }
          ]
        },
        {
          id: 'vegetables',
          label: 'Vegetables',
          children: [
            { id: 'corn', label: 'Corn 🌽' },
            { id: 'carrot', label: 'Carrot 🥕' },
            { id: 'eggplant', label: 'Eggplant 🍆' },
            { id: 'tomato', label: 'Tomato 🍅' }
          ]
        }
      ];
    },
    handleValue() {
      console.log(this.dlgData);
    }
  }
};
</script>

:::

属性

属性名类型默认说明可选值
dataListsArray--
dataFieldObject--
dataDisabledArray-禁用对应的选项(根据value)-
placeholderString-输入框占位文本-
disabledBoolenfalse是否禁止-
v-modelString-数据双向绑定-
clearablebooleantrue清空按钮-
sizeString-尺寸medium / small / mini
accordionfalse是否收起
multiplefalse是否多选
clearablefalse是否开启清除按钮
  • [ dataLists ] 说明
    设置选项,默认格式为 {label:"选项1",value:"1"} ,label 作为选项名,value 作为选中的返回值

  • [ dataField ] 说明
    自定数据字段,如果你的数据是这种格式 {text:"选项1",val:"1"} ,只需要用该属性 传入 {label:"text",value:"val"} 组件会将 text 作为 label ,val 作为 value 进行渲染

Copyright © 2017 10yun.com | 十云提供计算服务-IPV6 | ctocode组开发