vue树形控件tree的使用方法

 更新时间:2022年03月30日 09:23:51   作者:牵手北京99  
这篇文章主要为大家详细介绍了vue树形控件tree的使用方法,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

本文实例为大家分享了vue树形控件tree使用的具体代码,供大家参考,具体内容如下

<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: '一级 2',
          children: [{
            id: 3,
            label: '二级 2-1',
            children: [{
              id: 4,
              label: '三级 3-1-1'
            }, {
              id: 5,
              label: '三级 3-1-2',
              disabled: true
            }]
          }, {
            id: 2,
            label: '二级 2-2',
            disabled: true,
            children: [{
              id: 6,
              label: '三级 3-2-1'
            }, {
              id: 7,
              label: '三级 3-2-2',
              disabled: true,
              children: [{
                id: 8,
                label: '二级 8-1',
                children: [{
                  id: 9,
                  label: '三级 3-1-1'
                }, {
                  id: 10,
                  label: '三级 3-1-2',
                  disabled: true
                }]
              }]
            }]
          }]
        }],
        defaultProps: {
          // 用于修改节点指定标签的属性值
          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>
/* 树形结构节点添加连线 */
.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>

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

相关文章

  • el-table点击某一行高亮并显示小圆点的实现代码

    el-table点击某一行高亮并显示小圆点的实现代码

    这篇文章主要介绍了el-table点击某一行高亮并显示小圆点,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
    2022-08-08
  • Vue 2.0入门基础知识之内部指令详解

    Vue 2.0入门基础知识之内部指令详解

    这篇文章主要介绍了Vue 2.0入门基础知识之内部指令知识,非常不错,具有参考借鉴价值 ,需要的朋友可以参考下
    2017-10-10
  • Vue.js 中的 $watch使用方法

    Vue.js 中的 $watch使用方法

    本篇文章中主要介绍了Vue.js 中的 $watch使用方法,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2017-05-05
  • vue项目中swiper轮播active图片实现居中并放大

    vue项目中swiper轮播active图片实现居中并放大

    这篇文章主要介绍了vue项目中swiper轮播active图片实现居中并放大方式,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教
    2023-05-05
  • vue 组件prop验证作用示例解析

    vue 组件prop验证作用示例解析

    这篇文章主要为大家介绍了vue组件prop验证作用示例解析,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪
    2023-08-08
  • vue出现Uncaught SyntaxError:Unexpected token问题及解决

    vue出现Uncaught SyntaxError:Unexpected token问题及解决

    这篇文章主要介绍了vue出现Uncaught SyntaxError:Unexpected token问题及解决,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教
    2024-04-04
  • 一文详解如何在Vue3中使用jsx/tsx

    一文详解如何在Vue3中使用jsx/tsx

    本篇文章旨在带领大家快速了解和使用 Vue 中的 JSX 语法,好让大家在 Vue 中遇到或使用 JSX 的时候能很快入手,感兴趣的小伙伴可以跟随小编一起学习一下
    2023-03-03
  • Vue3+Tsx给路由加切换动画时的踩坑及解决

    Vue3+Tsx给路由加切换动画时的踩坑及解决

    这篇文章主要介绍了Vue3+Tsx给路由加切换动画时的踩坑及解决,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教
    2023-01-01
  • 如何使用Vue3设计实现一个Model组件浅析

    如何使用Vue3设计实现一个Model组件浅析

    v-model在Vue里面是一个语法糖,数据的双向绑定,本质上还是通过 自定义标签的attribute传递和接受,下面这篇文章主要给大家介绍了关于如何使用Vue3设计实现一个Model组件的相关资料,需要的朋友可以参考下
    2022-08-08
  • Vue路由模式中的hash和history模式详细介绍

    Vue路由模式中的hash和history模式详细介绍

    VUE分为两种路由模式分别是hash(哈希)和history,他们的区别是hash模式不会包含在http请求中,并且不会重新加载页面,而使用history模式的话,如果前端的url和后端发起请求的url不一致的话,会报404错误,所以使用history模式的话我们需要和后端进行配合
    2022-09-09

最新评论