国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

Vue.js組件tree實現省市多級聯動

2019-11-19 18:42:14
字體:
來源:轉載
供稿:網友

小穎在上一篇隨筆中寫了兩級的tree,下面給大家再分享一下用<ul><li>標簽實現省市多級聯動。

調用示例:

<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: '碑林區'  }, {  text: '雁塔區'  }, {  text: '未央區區'  }, {  text: '新城區'  }]  }, {  text: '安康市'  }, {  text: '咸陽市',  children: [{  text: '秦都區'  }, {  text: '渭城區'  }]  }, {  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前端組件學習教程》,歡迎大家學習閱讀。

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持武林網。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 房山区| 舒城县| 金平| 上蔡县| 大丰市| 会理县| 阿鲁科尔沁旗| 福海县| 迁西县| 吉水县| 平江县| 永川市| 眉山市| 茌平县| 濉溪县| 平泉县| 沅陵县| 修武县| 康保县| 汝城县| 大埔县| 航空| 马鞍山市| 章丘市| 凤凰县| 安康市| 阳曲县| 万州区| 布拖县| 开江县| 南江县| 微山县| 武穴市| 双峰县| 安泽县| 临邑县| 郸城县| 城口县| 郸城县| 休宁县| 福安市|