vue樹(shù)形控件tree的使用方法
本文實(shí)例為大家分享了vue樹(shù)形控件tree使用的具體代碼,供大家參考,具體內(nèi)容如下

<template> ? <div class="hello tree-container"> ? ? <el-tree ? ? ? :data="data" ? ? ? show-checkbox ? ? ? node-key="id" ? ? ? class="tree" ? ? ? :allow-drop="allowDrop" ? ? ? :props="defaultProps" ? ? ? :default-expanded-keys="[2, 3]" ? ? ? :default-checked-keys="[5]"> ? ? </el-tree> ? </div> </template>
<script>
export default {
? name: 'HelloWorld',
? data () {
? ? return {
? ? ? msg: 'Welcome to Your Vue.js App|',
? ? ? data: [{
? ? ? ? ? id: 1,
? ? ? ? ? label: '一級(jí) 2',
? ? ? ? ? children: [{
? ? ? ? ? ? id: 3,
? ? ? ? ? ? label: '二級(jí) 2-1',
? ? ? ? ? ? children: [{
? ? ? ? ? ? ? id: 4,
? ? ? ? ? ? ? label: '三級(jí) 3-1-1'
? ? ? ? ? ? }, {
? ? ? ? ? ? ? id: 5,
? ? ? ? ? ? ? label: '三級(jí) 3-1-2',
? ? ? ? ? ? ? disabled: true
? ? ? ? ? ? }]
? ? ? ? ? }, {
? ? ? ? ? ? id: 2,
? ? ? ? ? ? label: '二級(jí) 2-2',
? ? ? ? ? ? disabled: true,
? ? ? ? ? ? children: [{
? ? ? ? ? ? ? id: 6,
? ? ? ? ? ? ? label: '三級(jí) 3-2-1'
? ? ? ? ? ? }, {
? ? ? ? ? ? ? id: 7,
? ? ? ? ? ? ? label: '三級(jí) 3-2-2',
? ? ? ? ? ? ? disabled: true,
? ? ? ? ? ? ? children: [{
? ? ? ? ? ? ? ? id: 8,
? ? ? ? ? ? ? ? label: '二級(jí) 8-1',
? ? ? ? ? ? ? ? children: [{
? ? ? ? ? ? ? ? ? id: 9,
? ? ? ? ? ? ? ? ? label: '三級(jí) 3-1-1'
? ? ? ? ? ? ? ? }, {
? ? ? ? ? ? ? ? ? id: 10,
? ? ? ? ? ? ? ? ? label: '三級(jí) 3-1-2',
? ? ? ? ? ? ? ? ? disabled: true
? ? ? ? ? ? ? ? }]
? ? ? ? ? ? ? }]
? ? ? ? ? ? }]
? ? ? ? ? }]
? ? ? ? }],
? ? ? ? defaultProps: {
? ? ? ? ? // 用于修改節(jié)點(diǎn)指定標(biāo)簽的屬性值
? ? ? ? ? children: 'children',
? ? ? ? ? label: 'label'
? ? ? ? }
? ? }
? },
? methods: {
? ? allowDrop(draggingNode, dropNode, type) {
? ? ? ? if (draggingNode.parrent.id=== dropNode.parrent.id) {
? ? ? ? ? return type !== 'next';
? ? ? ? } else {
? ? ? ? ? return true;
? ? ? ? }
? ? ? }
? }
}
</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
/* 樹(shù)形結(jié)構(gòu)節(jié)點(diǎn)添加連線 */
.tree /deep/ .el-tree-node {
? position: relative;
? padding-left: 16px;
}
?
.tree /deep/ .el-tree-node__children {
? padding-left: 12px;
}
?
.tree /deep/ .el-tree-node :last-child:before {
? height: 50px;
}
.tree /deep/ > .el-tree-node:before {
? border: none !important;
}
.tree /deep/ .el-tree > .el-tree-node:before {
? border-left: none;
}
?
.tree-container /deep/ .el-tree > .el-tree-node:after {
? border-top: none;
}
?
.tree /deep/ .el-tree-node:before {
? content: "";
? left: -4px;
? position: absolute;
? right: auto;
? border-width: 1px;
}
?
.tree /deep/ .el-tree-node:after {
? content: "";
? left: -4px;
? position: absolute;
? right: auto;
? border-width: 1px;
}
.tree /deep/ .el-tree-node__expand-icon.is-leaf {
? display: none;
}
?
.tree /deep/ .el-tree-node:before {
? border-left: 1px solid #b8b9bb;
? bottom: 0px;
? height: 100%;
? top: -26px;
? width: 1px;
}
?
.tree /deep/ .el-tree-node:after {
? border-top: 1px solid #b8b9bb;
? height: 20px;
? top: 24px;
? width: 20px;
}
.tree /deep/ .el-tree-node__expand-icon{
? display: none;
}
.tree /deep/ .el-tree-node__content{
? padding-left: 0 !important;
}
.tree /deep/ .el-tree-node__content {
? height: 18px;padding-top: 16px;
}
</style>以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
el-table點(diǎn)擊某一行高亮并顯示小圓點(diǎn)的實(shí)現(xiàn)代碼
這篇文章主要介紹了el-table點(diǎn)擊某一行高亮并顯示小圓點(diǎn),本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-08-08
Vue 2.0入門(mén)基礎(chǔ)知識(shí)之內(nèi)部指令詳解
這篇文章主要介紹了Vue 2.0入門(mén)基礎(chǔ)知識(shí)之內(nèi)部指令知識(shí),非常不錯(cuò),具有參考借鑒價(jià)值 ,需要的朋友可以參考下2017-10-10
vue項(xiàng)目中swiper輪播active圖片實(shí)現(xiàn)居中并放大
這篇文章主要介紹了vue項(xiàng)目中swiper輪播active圖片實(shí)現(xiàn)居中并放大方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-05-05
vue出現(xiàn)Uncaught SyntaxError:Unexpected token問(wèn)題及解決
這篇文章主要介紹了vue出現(xiàn)Uncaught SyntaxError:Unexpected token問(wèn)題及解決,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-04-04
Vue3+Tsx給路由加切換動(dòng)畫(huà)時(shí)的踩坑及解決
這篇文章主要介紹了Vue3+Tsx給路由加切換動(dòng)畫(huà)時(shí)的踩坑及解決,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-01-01
如何使用Vue3設(shè)計(jì)實(shí)現(xiàn)一個(gè)Model組件淺析
v-model在Vue里面是一個(gè)語(yǔ)法糖,數(shù)據(jù)的雙向綁定,本質(zhì)上還是通過(guò) 自定義標(biāo)簽的attribute傳遞和接受,下面這篇文章主要給大家介紹了關(guān)于如何使用Vue3設(shè)計(jì)實(shí)現(xiàn)一個(gè)Model組件的相關(guān)資料,需要的朋友可以參考下2022-08-08
Vue路由模式中的hash和history模式詳細(xì)介紹
VUE分為兩種路由模式分別是hash(哈希)和history,他們的區(qū)別是hash模式不會(huì)包含在http請(qǐng)求中,并且不會(huì)重新加載頁(yè)面,而使用history模式的話,如果前端的url和后端發(fā)起請(qǐng)求的url不一致的話,會(huì)報(bào)404錯(cuò)誤,所以使用history模式的話我們需要和后端進(jìn)行配合2022-09-09

