给我一个vue 甘特图的示例和解析

时间: 2024-02-24 11:57:51 浏览: 17
好的,下面为您提供一个 Vue 甘特图的示例和解析。 示例代码如下: ``` <template> <div class="gantt-chart"> <div class="gantt-header"> <div class="gantt-task-name">任务名称</div> <div class="gantt-task-date">开始时间</div> <div class="gantt-task-date">结束时间</div> </div> <div class="gantt-body"> <div v-for="task in tasks" :key="task.id" class="gantt-task" :style="{ width: task.width + '%', left: task.left + '%' }"> <div class="gantt-task-name">{{ task.name }}</div> <div class="gantt-task-date">{{ task.start }}</div> <div class="gantt-task-date">{{ task.end }}</div> </div> </div> </div> </template> <script> export default { data() { return { tasks: [ { id: 1, name: '任务1', start: '2021-01-01', end: '2021-01-10', width: 10, left: 0 }, { id: 2, name: '任务2', start: '2021-01-05', end: '2021-01-15', width: 10, left: 10 }, { id: 3, name: '任务3', start: '2021-01-10', end: '2021-01-20', width: 10, left: 20 }, { id: 4, name: '任务4', start: '2021-01-15', end: '2021-01-25', width: 10, left: 30 }, { id: 5, name: '任务5', start: '2021-01-20', end: '2021-01-30', width: 10, left: 40 }, { id: 6, name: '任务6', start: '2021-01-25', end: '2021-02-04', width: 10, left: 50 }, { id: 7, name: '任务7', start: '2021-01-28', end: '2021-02-07', width: 10, left: 60 }, { id: 8, name: '任务8', start: '2021-02-01', end: '2021-02-10', width: 10, left: 70 }, { id: 9, name: '任务9', start: '2021-02-05', end: '2021-02-15', width: 10, left: 80 }, { id: 10, name: '任务10', start: '2021-02-10', end: '2021-02-20', width: 10, left: 90 } ] } } } </script> <style scoped> .gantt-chart { position: relative; width: 100%; height: 300px; border: 1px solid #ccc; } .gantt-header { height: 30px; background: #f5f5f5; display: flex; align-items: center; } .gantt-task-name { flex: 2; text-align: center; } .gantt-task-date { flex: 1; text-align: center; } .gantt-body { position: absolute; top: 30px; bottom: 0; left: 0; right: 0; display: flex; overflow: hidden; } .gantt-task { position: absolute; top: 0; bottom: 0; background: #2196f3; color: #fff; padding: 5px; box-sizing: border-box; border-radius: 5px; display: flex; flex-direction: column; justify-content: center; } </style> ``` 代码解析: 1. 在 data 中定义了一个 tasks 数组,数组中包含了 10 个任务的信息,包括任务名称、开始时间、结束时间、宽度和左偏移量。 2. 在模板中,使用 v-for 遍历 tasks 数组,为每个任务创建一个 div 元素,使用 CSS 样式设置它的宽度和左偏移量。 3. 使用 CSS 样式设置任务 div 元素的位置、背景颜色、边框等样式。 4. 使用 CSS 样式设置任务名称和时间的样式。 5. 将任务名称和时间渲染到任务 div 元素中。 6. 整个甘特图的样式由外层的 gantt-chart 和 gantt-body 控制,其中 gantt-body 中包含了所有的任务 div 元素。 7. 为了方便展示,使用了固定的高度和宽度,实际使用时可以根据需要动态计算宽度和位置。 这是一个简单的 Vue 甘特图示例,您可以根据需要进行修改和扩展。

相关推荐

最新推荐

recommend-type

vue+springboot图片上传和显示的示例代码

主要介绍了vue+springboot图片上传和显示的示例代码,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
recommend-type

nginx部署多个vue项目的方法示例

主要介绍了nginx部署多个vue项目的方法示例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
recommend-type

vue 使用高德地图vue-amap组件过程解析

主要介绍了vue 使用高德地图vue-amap组件过程解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
recommend-type

使用Vue组件实现一个简单弹窗效果

主要介绍了使用Vue组件实现一个简单弹窗效果,本文主要内容会涉及到弹窗遮罩的实现, slot 插槽的使用方式,props 、 $emit 传参,具体组件代码也传上去了。需要的朋友可以参考下
recommend-type

vue实现的上传图片到数据库并显示到页面功能示例

主要介绍了vue实现的上传图片到数据库并显示到页面功能,结合实例形式分析了基于vue.js的数据库操作及页面图片显示相关操作技巧,需要的朋友可以参考下
recommend-type

zigbee-cluster-library-specification

最新的zigbee-cluster-library-specification说明文档。
recommend-type

管理建模和仿真的文件

管理Boualem Benatallah引用此版本:布阿利姆·贝纳塔拉。管理建模和仿真。约瑟夫-傅立叶大学-格勒诺布尔第一大学,1996年。法语。NNT:电话:00345357HAL ID:电话:00345357https://theses.hal.science/tel-003453572008年12月9日提交HAL是一个多学科的开放存取档案馆,用于存放和传播科学研究论文,无论它们是否被公开。论文可以来自法国或国外的教学和研究机构,也可以来自公共或私人研究中心。L’archive ouverte pluridisciplinaire
recommend-type

【实战演练】MATLAB用遗传算法改进粒子群GA-PSO算法

![MATLAB智能算法合集](https://static.fuxi.netease.com/fuxi-official/web/20221101/83f465753fd49c41536a5640367d4340.jpg) # 2.1 遗传算法的原理和实现 遗传算法(GA)是一种受生物进化过程启发的优化算法。它通过模拟自然选择和遗传机制来搜索最优解。 **2.1.1 遗传算法的编码和解码** 编码是将问题空间中的解表示为二进制字符串或其他数据结构的过程。解码是将编码的解转换为问题空间中的实际解的过程。常见的编码方法包括二进制编码、实数编码和树形编码。 **2.1.2 遗传算法的交叉和
recommend-type

openstack的20种接口有哪些

以下是OpenStack的20种API接口: 1. Identity (Keystone) API 2. Compute (Nova) API 3. Networking (Neutron) API 4. Block Storage (Cinder) API 5. Object Storage (Swift) API 6. Image (Glance) API 7. Telemetry (Ceilometer) API 8. Orchestration (Heat) API 9. Database (Trove) API 10. Bare Metal (Ironic) API 11. DNS
recommend-type

JSBSim Reference Manual

JSBSim参考手册,其中包含JSBSim简介,JSBSim配置文件xml的编写语法,编程手册以及一些应用实例等。其中有部分内容还没有写完,估计有生之年很难看到完整版了,但是内容还是很有参考价值的。