cascader级联选择器

... 2022-9-15 About 1 min

# cascader级联选择器

值:[ "zhinan", "shejiyuanze", "yizhi" ]
返回单节点:zhinan
仅显示最后一级值:[ "zhinan", "shejiyuanze", "yizhi" ]
多选:[ [ "zhinan", "shejiyuanze", "yizhi" ] ]
选择任意一级选项:[ "zhinan", "shejiyuanze", "yizhi" ]
懒加载值:[ "110000", "110100", "110101" ]
<el-row :span="24">
  <el-col :span="6">
   值:{{form}}<br/>
   <avue-cascader v-model="form" :dic="dic"></avue-cascader>
  </el-col>
  <el-col :span="24"></el-col>
   <el-col :span="6">
   返回单节点:{{form3}}<br/>
   <avue-cascader :emit-path="false" check-strictly v-model="form3"  :dic="dic"></avue-cascader>
  </el-col>
  <el-col :span="24"></el-col>
   <el-col :span="6">
   仅显示最后一级值:{{form}}<br/>
   <avue-cascader v-model="form" :show-all-levels="false" :dic="dic"></avue-cascader>
  </el-col>
   <el-col :span="24"></el-col>
   <el-col :span="6">
   多选:{{form2}}<br/>
   <avue-cascader v-model="form2" multiple :dic="dic"></avue-cascader>
  </el-col>
  <el-col :span="24"></el-col>
   <el-col :span="6">
   选择任意一级选项:{{form}}<br/>
   <avue-cascader v-model="form" check-strictly :dic="dic"></avue-cascader>
  </el-col>
  <el-col :span="24"></el-col>
   <el-col :span="6">
   懒加载值:{{form1}}<br/>
   <avue-cascader  lazy :lazy-load="lazyLoad" :props="props" v-model="form1" ></avue-cascader>
  </el-col>
</el-row>
<script>
export default {
    data() {
      return {
        form:[ "zhinan", "shejiyuanze", "yizhi" ],
        form1:[ "110000", "110100", "110101" ],
        form2:[ [ "zhinan", "shejiyuanze", "yizhi" ]],
        form3:'zhinan',
        props: {
          label: 'name',
          value: 'code'
        },
        dic:[{
          value: 'zhinan',
          label: '指南',
          children: [{
            value: 'shejiyuanze',
            label: '设计原则',
            children: [{
              value: 'yizhi',
              label: '一致'
            }, {
              value: 'fankui',
              label: '反馈'
          }]
        }]
      }]
    }
  },
  methods:{
    lazyLoad(node, resolve) {
      let baseUrl = 'https://cli.avuejs.com/api/area'
      let stop_level = 2;
      let level = node.level;
      let data = node.data || {}
      let code = data.code;
      let list = [];
      let callback = () => {
        resolve((list || []).map(ele => {
          return Object.assign(ele, {
            leaf: level >= stop_level
          })
        }));
      }
      if (level == 0) {
        axios.get(`${baseUrl}/getProvince`).then(res => {
          list = res.data.data;
          callback()
        })
      }
      if (level == 1) {
        axios.get(`${baseUrl}/getCity/${code}`).then(res => {
          list = res.data.data;
          callback()
        })
      } else if (level == 2) {
        axios.get(`${baseUrl}/getArea/${code}`).then(res => {
          list = res.data.data;
          callback()
        })
      }else{
         callback()
      }
    }
  }
}
</script>

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
Expand Copy
Last update: October 16, 2022 17:07
Contributors: smallwei
您正在浏览基于 Vue 2.x 的 Avue 文档; 点击这里 查看 Vue 3.x 的升级版本