elementUI實現(xiàn)級聯(lián)選擇器
更新時間:2021年11月09日 11:45:57 作者:倉央1143
這篇文章主要為大家詳細介紹了elementUI實現(xiàn)級聯(lián)選擇器,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文實例為大家分享了elementUI實現(xiàn)級聯(lián)選擇器的具體代碼,供大家參考,具體內(nèi)容如下
1、從后端調(diào)用接口,傳遞數(shù)據(jù)到前端
2、使用VUE代碼顯示級聯(lián)選項
<el-cascader :disabled="isDisabled" :props="defaultParams" :options="options" v-model="selectedOptions" :show-all-levels="false" filterable :clearable="true" ></el-cascader>
3、定義JS
data() { options: [], selectedOptions: [], defaultParams: { label: "name", value: "code", children: "children", }, }, created() { listArea(330000).then((response) => { console.log(response); this.options = this.getTreeData(response); this.loading = false; }); }, methods: { // 遞歸消除空數(shù)組 getTreeData(data) { // 循環(huán)遍歷json數(shù)據(jù) for (var i = 0; i < data.length; i++) { if (data[i].children.length < 1) { // children若為空數(shù)組,則將children設為undefined data[i].children = undefined; } else { // children若不為空數(shù)組,則繼續(xù) 遞歸調(diào)用 本方法 this.getTreeData(data[i].children); } } return data; } }
4、顯示效果如下
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關文章
vue使用jsencrypt實現(xiàn)rsa前端加密的操作代碼
這篇文章主要介紹了vue使用jsencrypt實現(xiàn)rsa前端加密,本文通過實例代碼給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2023-09-09Vue報錯:Injection?"xxxx"?not?found的解決辦法
這篇文章主要給大家介紹了關于Vue報錯:Injection?"xxxx"?not?found的解決辦法,文中通過圖文將解決的辦法介紹的非常詳細,對大家的學習具有一定的參考借鑒價值,需要的朋友可以參考下2023-07-07