elementuiPlus el-cascader限制级别选择
    		       		warning:
    		            这篇文章距离上次修改已过429天,其中的内容可能已经有所变动。
    		        
        		                
                在 Element UI Plus 中,el-cascader 组件可以通过设置 props 属性中的 checkStrictly 来控制是否严格限制级别选择。如果你想要限制用户只能选择到某一个特定的级别,可以将 checkStrictly 设置为 true。
以下是一个简单的例子:
<template>
  <el-cascader
    :options="options"
    v-model="selectedValue"
    :props="{ checkStrictly: true }"
  ></el-cascader>
</template>
 
<script>
import { ref } from 'vue';
 
export default {
  setup() {
    const selectedValue = ref([]);
    const options = ref([
      {
        value: 'guid1',
        label: 'Node 1',
        children: [
          {
            value: 'guid-1-1',
            label: 'Child 1-1'
          },
          {
            value: 'guid-1-2',
            label: 'Child 1-2',
            children: [
              {
                value: 'guid-1-2-1',
                label: 'Child 1-2-1'
              }
            ]
          }
        ]
      },
      {
        value: 'guid2',
        label: 'Node 2'
      }
    ]);
 
    return { selectedValue, options };
  }
};
</script>在这个例子中,el-cascader 的 options 属性定义了级联选项,props 中的 checkStrictly 设置为 true 表示只能选择到最后一个层级的选项,不能再选择子选项。用户的选择将被绑定到 selectedValue 这个响应式数据上。
评论已关闭