vue2.0图片查看器

一个 vue2.0的图片查看器

闲暇下来封装了一个 vue2.0的图片查看器组件,通过这个更能方便清楚地查看列表的一张张图片。已经兼容 pc 跟移动端,通过 npm 来下载安装使用。
This is an example

1、安装

npm install vue-imageview --save

2、使用

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
// example
<template>
<div class="hello">
<transition name="slide-fade" class="fadeView">
<div v-if="show">
<image-view :imgArr="imgArr"
:showImageView="true"
:imageIndex="imageIndex"
v-on:hideImage="hideImageView"></image-view>
</div>
</transition>
<h1 @click="showImgView">显示隐藏</h1>
<img v-for="(item, index) in imgArr" :src="item" @click="selectImg(index)">
</div>
</template>
<script>
import imageView from './imageView.vue'
export default {
name: 'hello',
components: {
'image-view': imageView
},
data () {
return {
// 图片数组
imgArr: ['/public/img/1.jpeg', '/public/img/2.jpeg', '/public/img/2.jpeg', '/public/img/3.jpeg', '/public/img/4.jpeg', '/public/img/5.jpeg', '/public/img/6.jpeg'],
// 显示组件
show: false,
// 从哪一张图片开始
imageIndex: 0
}
},
methods: {
showImgView () {
this.show = true
},
hideImageView () {
this.show = false
},
selectImg (index) {
this.show = true
this.imageIndex = index
}
}
}
</script>
<style scoped>
.slide-fade-enter-active {
transition: opacity .5s ease;
}
.slide-fade-leave-active {
transition: opacity .5s ease;
}
.slide-fade-enter, .slide-fade-leave-active {
opacity: 0;
}
h1, h2 {
margin: 0;
padding: 0;
}
img {
display: block;
margin: 10px auto;
max-width: 400px;
}
</style>

3、参数配置

































参数 类型 说明 必要
imgArr array 图片数组 是
show blooean 显示组件开关 是
imageIndex number 从第几张图片开始显示 否
hideImageView function 关闭图片查看器函数 是
文章目录
  1. 1. 一个 vue2.0的图片查看器
  2. 2. 1、安装
  3. 3. 2、使用
  4. 4. 3、参数配置
|