直接上代码,使用的接口还是上一篇文章的给出的接口。
实现懒加载数据。
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
| <template> <div class="block"> <el-cascader v-model="value" :props="props" @change="handleChange"></el-cascader> </div> </template> <script> import { getprovinces, getcities, getareas, getstreets } from '@/api/riskarea' export default { data () { return { value: [], props: { value: 'code', label: 'name', lazy: true, async lazyLoad (node, resolve) { console.log(node) const { level } = node if (node.level === 0) { return resolve(await getprovinces()) } else if (node.level === 1) { return resolve(await getcities(node.value)) } else if (level === 2) { return resolve(await getareas(node.value)) } else if (level === 3) { return resolve(await getstreets(node.value)) } else { return resolve([]) } } } } }, methods: { handleChange (value) { console.log(value) } } } </script> <style></style>
|