forked from youzan/vant
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.vue
More file actions
130 lines (115 loc) · 2.52 KB
/
Copy pathindex.vue
File metadata and controls
130 lines (115 loc) · 2.52 KB
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<template>
<demo-section>
<demo-block :title="$t('basicUsage')">
<van-button
type="primary"
@click="showImagePreview"
>
{{ $t('button1') }}
</van-button>
</demo-block>
<demo-block :title="$t('button2')">
<van-button
type="primary"
@click="showImagePreview(1)"
>
{{ $t('button2') }}
</van-button>
</demo-block>
<demo-block :title="$t('button3')">
<van-button
type="primary"
@click="showImagePreview(0, 1000)"
>
{{ $t('button3') }}
</van-button>
</demo-block>
<demo-block :title="$t('componentCall')">
<van-button
type="primary"
@click="componentCall"
>
{{ $t('componentCall') }}
</van-button>
<van-image-preview
v-model="show"
:images="images"
:swipe-duration="300"
@change="onChange"
>
<template #index>{{ $t('index', index) }}</template>
</van-image-preview>
</demo-block>
</demo-section>
</template>
<script>
import { ImagePreview } from '../..';
const images = [
'https://img.yzcdn.cn/vant/apple-1.jpg',
'https://img.yzcdn.cn/vant/apple-2.jpg',
'https://img.yzcdn.cn/vant/apple-3.jpg',
'https://img.yzcdn.cn/vant/apple-4.jpg'
];
export default {
i18n: {
'zh-CN': {
button1: '预览图片',
button2: '指定初始位置',
button3: '异步关闭',
componentCall: '组件调用',
index: index => `第${index + 1}页`
},
'en-US': {
button1: 'Show Images',
button2: 'Custom Start Position',
button3: 'Async Close',
componentCall: 'Component Call',
index: index => `Page: ${index}`
}
},
data() {
return {
show: false,
images,
index: 0
};
},
methods: {
componentCall() {
this.show = true;
},
onChange(index) {
this.index = index;
},
showImagePreview(position, timer) {
const instance = ImagePreview({
images,
lazyLoad: true,
swipeDuration: 300,
asyncClose: !!timer,
closeOnPopstate: true,
startPosition: typeof position === 'number' ? position : 0
});
if (timer) {
setTimeout(() => {
instance.close();
}, timer);
}
}
}
};
</script>
<style lang="less">
@import "../../style/var";
.demo-image-preview {
background-color: @white;
.van-button {
margin-left: @padding-md;
}
}
.van-image-preview {
img {
-webkit-user-drag: none;
}
}
</style>