首页 > 其他分享 >vue2项目中使用 vue2-org-tree组件实现组织架构图

vue2项目中使用 vue2-org-tree组件实现组织架构图

时间:2022-11-14 11:44:25浏览次数:82  
标签:showInfo tree label vue2 org 架构图 data

1. 安装及使用操作流程

npm安装:
npm i vue2-org-tree
安装loader,不然会报错
npm install --save-dev less less-loader

main.js文件引入并使用: import Vue2OrgTree from 'vue2-org-tree' import 'vue2-org-tree/dist/style.css'; Vue.use(Vue2OrgTree);

2.具体实现代码

进入页面:
<template>
<div class="tree-container">
<vue2-org-tree
:data="treeData"
:renderContent="renderContent"
@on-node-mouseover="handleNodeMouseover"
@on-node-mouseout="handleNodeMouseout"
@on-node-click="handelNodeClick"
/>
// 创建浮窗容器
<div class="show-info" v-show="showInfo">
<p>用户名称:xxx</p>
<p>联系电话:xxx</p>
<p>联系地址:xxx</p>
...
</div>
</div>
</template>
<script>
export default {
data(){
return {
treeData: {
id: 0,
label: 'xxx',
children: [
{
id: 2,
label: '0-2',
children: [
{
id: 5,
label: '0-2-5',
}
]
},
{
id: 3,
label: '0-3',
children: [
{
id: 6,
label: '0-3-6',
children: []
}
]
}
]
      },
info: {},//详情数据
}
},
methods:{
// 重新渲染展示文字的样式,满足判断条件的可以添加背景,文字高亮等
renderContent(h, data){
return(
<div class={data.id==='x'?'类名1':'类名2'}>
<span>{{data.label}}</span>
</div>
)
},
// 鼠标移入事件
handleNodeMouseOver(e, data){
this.info = data.info || {};
this.showInfo = true;
const showInfo = document.getElementsByClassName('show-info')[0];
showInfo.style.left = e.clientX + 'px';
showInfo.style.top = e.clientY + 'px';
},
// 鼠标移出事件
handleNodeMouseOut(e, data){
this.showInfo = false;
},
// 点击事件
handleNodeClick(e, data){
console.log(e, data); //可以获取到点击的节点数据,然后可以做一些逻辑处理,比如请求接口等
}
},
}
</script>
<style lang="less">
.show-info {
position: absolute;
top: 0;
left: 0;
background: rgba(0,0,0,.7);
color: #fff;
border-radius: 15px;
padding: 15px;
transition: all 0.3s;
z-index:999;
text-align: left;
font-size: 12px;
}
</style>

3.效果

 

 

 

参考链接:

      https://github.com/hukaibaihu/vue-org-tree

      https://www.cnblogs.com/trampeagle/p/13432335.html

     https://blog.csdn.net/yehaocheng520/article/details/119675805

标签:showInfo,tree,label,vue2,org,架构图,data
From: https://www.cnblogs.com/sunnyeve/p/16888503.html

相关文章

  • 【Vue2-04】scoped样式
    scoped样式作用:让样式在局部生效,防止冲突写法:<stylescoped><template><div></div></template><script>exportdefault{}</script......
  • 【Vue2-02】ref属性
    ref属性被用来给元素或子组件注册引用信息(id的替代者)应用在html标签上获取的是真实DOM元素,应用在组件标签上是组件实例对象(vc)使用方式:打标识:<h1ref="xxx">...</......
  • 【Vue2-03】props属性
    props配置功能:让组件接收外部传过来的数据数据传递:<Demoname="xxx">接收数据:方式一(只接收): props:['name'] 方式二(限制类型): props:{ name:String......
  • 【Vue2-01】Vue脚手架
    Vue脚手架一、单文件组件1.单文件组件定义单文件组件:*.vue文件,类似HTML格式的文件。Vue的单文件组件会将一个组件的逻辑(JavaScript)、模板(HTML)和样式(CSS)封装在同......
  • CodeForces - 1187E Tree Painting
    题意:给出一棵树,最开始所有节点都是白的。进行一些操作来计算树的价值。每次操作可以选一个节点,给价值加上包括这个结点在内的白色连通块大小。然后把这个结点染成黑色。除......
  • CodeForces - 1092F Tree with Maximum Cost
    题意:给出一棵树,每个结点有一个权值。定义一棵树以ai为根节点的价值为 剩下每个结点到根节点的距离乘权值 之和。求这棵树的最大价值。解:随便选一个结点为根,从下到上统......
  • TS 创建TreeNode类型
    想要实现的效果如:创建一个区域类,包含区域名称name,区域编码code,子区域childreninterfaceArea{name:string,code:string,children:Array<Area>}......
  • 运行npm install 时,卡在sill idealTree buildDeps没有反应
    .运行npminstall时,卡在sillidealTreebuildDeps没有反应npminstall一直停留在fetchMetadata:sillmapToRegistryurihttp://registry.npmjs.org/whatwg-fetch可以......
  • 14. Vue2 和 Vue3 区别
    主要分为四点:1.Vue3使用了proxy替代了Object.defineProperty实现响应式数据,所以vue3的性能得到了提升;2.Vue3可以在template模板使用多个根标......
  • 13. 说一下$set,用在Vue2还是Vue3
    $set是vue2中对象用来追加响应式数据的方法;使用格式:$set(对象,属性名,值) vue3中使用proxy替代了Object.defineProperty实现对象的响应式数据,所以在......