Vue.js組件tree實現(xiàn)省市多級聯(lián)動
更新時間:2022年07月15日 15:30:52 作者:愛喝酸奶的吃貨
這篇文章主要為大家詳細介紹了Vue.js組件tree實現(xiàn)省市多級聯(lián)動的相關(guān)資料,具有一定的參考價值,感興趣的小伙伴們可以參考一下
小穎在上一篇隨筆中寫了兩級的tree,下面給大家再分享一下用<ul><li>標簽實現(xiàn)省市多級聯(lián)動。
調(diào)用示例:
<template> <div> <treeview :model='treedata'></treeview> </div> </template> <script> import treeview from './TreeView.vue' export default { components: { treeview }, props: { }, method:{ }, ready:function(){ }, data(){ return { treedata:{text:'地域', children: [{ text: '中國', children: [{ text: '陜西省', children: [{ text: '西安市', children: [{ text: '碑林區(qū)' }, { text: '雁塔區(qū)' }, { text: '未央?yún)^(qū)區(qū)' }, { text: '新城區(qū)' }] }, { text: '安康市' }, { text: '咸陽市', children: [{ text: '秦都區(qū)' }, { text: '渭城區(qū)' }] }, { text: '渭南市' }] }, { text: '四川省', children: [{ text: '成都市' }, { text: '綿陽市' }, { text: '廣元市' }] }, { text: '安徽省' }] }, { text: '俄羅斯' }]}} } } </script>
組件代碼:
<style scoped> ul,li{ list-style-type: none; } </style> <template> <li> <div @click='toggle'><span v-if='hasLeaves'>[{{open ? '-' : '+'}}]</span>{{model.text}}</div> <ul> <treeview v-for='model in model.children' :model='model' v-show='open'></treeview> </ul> </li> </template> <script> export default { name: 'treeview', props: { model: { type: Object } }, methods: { toggle:function(){ this.open=!this.open; } }, ready: function() {}, computed:{ hasLeaves: function() { return this.model.children && this.model.children.length } }, data() { return { open: false } } } </script>
效果圖:
本文已被整理到了《Vue.js前端組件學(xué)習(xí)教程》,歡迎大家學(xué)習(xí)閱讀。
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Vue2實現(xiàn)圖片的拖拽,縮放和旋轉(zhuǎn)效果的示例代碼
這篇文章主要為大家介紹了如何基于vue2?實現(xiàn)圖片的拖拽、旋轉(zhuǎn)、鼠標滾動放大縮小等功能。文中的示例代碼講解詳細,感興趣的小伙伴可以嘗試一下2022-11-11Elementui?el-input輸入框校驗及表單校驗實例代碼
輸入框是使用非常多的元素,用來輸入用戶名、密碼等等信息,Element提供了功能和樣式豐富的輸入框,下面這篇文章主要給大家介紹了關(guān)于Elementui?el-input輸入框校驗及表單校驗的相關(guān)資料,需要的朋友可以參考下2023-06-06vue3實現(xiàn)動態(tài)側(cè)邊菜單欄的幾種方式簡單總結(jié)
在做開發(fā)中都會遇到的需求,每個用戶的權(quán)限是不一樣的,那他可以訪問的頁面(路由)可以操作的菜單選項是不一樣的,如果由后端控制,我們前端需要去實現(xiàn)動態(tài)路由,動態(tài)渲染側(cè)邊菜單欄,這篇文章主要給大家介紹了關(guān)于vue3實現(xiàn)動態(tài)側(cè)邊菜單欄的幾種方式,需要的朋友可以參考下2024-02-02