vue2引入vis-timeline
时间: 2023-09-30 21:02:54 浏览: 132
要在 Vue2 中引入 vis-timeline,需要先安装 vis-timeline 和 moment:
```
npm install vis moment --save
```
然后在 Vue 组件中引入 vis 和 moment:
```
import Vue from 'vue'
import vis from 'vis'
import moment from 'moment'
Vue.prototype.$vis = vis
Vue.prototype.$moment = moment
```
最后在组件中使用 vis-timeline:
```vue
<template>
<div ref="timeline"></div>
</template>
<script>
export default {
mounted() {
const container = this.$refs.timeline
const items = new this.$vis.DataSet([
{ id: 1, content: 'item 1', start: '2013-04-20' },
{ id: 2, content: 'item 2', start: '2013-04-14' },
{ id: 3, content: 'item 3', start: '2013-04-18' },
{ id: 4, content: 'item 4', start: '2013-04-16', end: '2013-04-19' },
{ id: 5, content: 'item 5', start: '2013-04-25' }
])
const options = {}
new this.$vis.Timeline(container, items, options)
}
}
</script>
```
阅读全文