0%

vue-time-line-npm的使用

本文介绍vue-time-line-npm如何使用,包括局部使用、和全局使用。目前功能比较简单,有切页、放大、缩小、还原功能。

安装

1
2
3
npm install vue-time-line-npm --save
# or 
yarn add vue-time-line-npm

全局引用

1
2
3
4
import Vue from 'vue'
import TimeLine from 'vue-time-line-npm'
 
Vue.use(TimeLine, /* { default options with global component } */)
示例1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<template>
<div class="home">
<TimeLine :pages="pageList" ref="timeline"></TimeLine>
<ul>
<li v-for="(page,p) in pageList" :class="['btn',{'active':activeIndex===p}]" @click="swicthPage(p)">{{p}}
</li>
<li @click="zoomIn" class="btn">放大</li>
<li @click="zoomOut" class="btn">缩小</li>
<li @click="back" class="btn">重置</li>
</ul>
</div>
</template>
<script>
export default {
data() {
return {
activeIndex: 0,
pageList: [{
id: 1,
name: "页签1",
duration: 3,
}, {
id: 2,
name: "页签2",
duration: 3,
}, {
id: 3,
name: "页签3",
duration: 3,
}]
}
},
methods: {
swicthPage(index) {
this.activeIndex = index;
this.$refs.timeline.switchPage(index);
},
zoomOut() {
this.$refs.timeline.zoomOut();
},
zoomIn() {
this.$refs.timeline.zoomIn();
},
back() {
this.$refs.timeline.backHome();
},
}
}
</script>
<style scoped lang="scss">
ul, li {
list-style: none;
}

li {
display: inline-flex;
}

.btn {
padding: 10px 20px;
border: 1px solid;
margin: 0 10px;
cursor: pointer;

&.active {
background-color: #f60;
color: #fff;
}
}
</style>

局部引用

1
2
3
4
5
6
7
import { TimeLine } from 'vue-time-line-npm'
 
export default {
  components: {
    TimeLine
  }
}
示例1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<template>
<div class="home">
<TimeLine :pages="pageList" ref="timeline"></TimeLine>
<ul>
<li v-for="(page,p) in pageList" :class="['btn',{'active':activeIndex===p}]" @click="swicthPage(p)">{{p}}
</li>
<li @click="zoomIn" class="btn">放大</li>
<li @click="zoomOut" class="btn">缩小</li>
<li @click="back" class="btn">重置</li>
</ul>
</div>
</template>
<script>
import {TimeLine} from 'vue-time-line-npm';

export default {
data() {
return {
activeIndex: 0,
pageList: [{
id: 1,
name: "页签1",
duration: 3,
}, {
id: 2,
name: "页签2",
duration: 3,
}, {
id: 3,
name: "页签3",
duration: 3,
}]
}
},
components: {
TimeLine
},
methods: {
swicthPage(index) {
this.activeIndex = index;
this.$refs.timeline.switchPage(index);
},
zoomOut() {
this.$refs.timeline.zoomOut();
},
zoomIn() {
this.$refs.timeline.zoomIn();
},
back() {
this.$refs.timeline.backHome();
},
}
}
</script>
<style scoped lang="scss">
ul, li {
list-style: none;
}

li {
display: inline-flex;
}

.btn {
padding: 10px 20px;
border: 1px solid;
margin: 0 10px;
cursor: pointer;

&.active {
background-color: #f60;
color: #fff;
}
}
</style>

更多

tips Wiki 文档:https://github.com/mingyangya/vue-time-line-npm/wiki