vue-image-swipe

基于photoswipe实现的vue图片预览组件

安装

1 第一步


npm install vue-image-swipe -D

2 第二步

vue 入口文件引入


import Vue from 'vue'
import VueImageSwipe from 'vue-image-swipe'
import 'vue-image-swipe/dist/vue-image-swipe.css'
Vue.use(VueImageSwipe)

使用


<template>
<div>
hello world
<div>
<ul>
<li
:key="index"
@click="preview(index)"
v-for="(l, index) in images">
<img :src="l" alt="">
</li>
</ul>
</div>
</div>
</template>
<script>
export default {
name: 'app',
data() {
return {
images: [
'http://oayhezji6.bkt.clouddn.com/preview1.jpg',
'http://oayhezji6.bkt.clouddn.com/preview2.jpg',
'http://oayhezji6.bkt.clouddn.com/preview3.jpg',
'http://oayhezji6.bkt.clouddn.com/preview9.jpg',
'http://oayhezji6.bkt.clouddn.com/preview10.jpg',
'http://oayhezji6.bkt.clouddn.com/preview6.jpg'
]
}
},
created() {
},
methods: {
preview(index) {
this.$imagePreview({
images: this.images,
index: index,
})
}
}
}
</script>

methods

只暴露了一个方法this.$imagePreview,并绑定到vue的原型上
使用


this.$imagePreview(options = {})

options有三个参数

参数 默认值 说明
images 空数组 图片的url数组
index 0 预览图片的索引值, 默认是0
defaultOpt {} 配置项

defaultOpt 的配置项请参考photoswipe配置项
注意:不能保证所有配置项都是可用的

列举一些常用的配置


defaultOpt: {
fullscreenEl: true,
shareEl: false,
arrowEl: true,
preloaderEl: true,
loop: false,
bgOpacity: 0.85,
showHideOpacity: true,
errorMsg: '<div class="pswp__error-msg">图片加载失败</div>',
}

demo

demo

查看源码

来源:https://segmentfault.com/a/1190000016409430

最新文章

  1. WinForm设置控件焦点focus
  2. shell中三种引号的用法
  3. SQL Server 2008 R2 未能加载文件或程序集Microsoft.SqlServer.Sqm...
  4. juqery 实现商城循环倒计时
  5. Java线程操作方法
  6. DAO接口及实现类
  7. 努力学习 HTML5 (4)—— 浏览器对语义元素的支持情况
  8. DB2中OLAP函数使用示例
  9. [转载]GMM的EM算法实现
  10. OSVERSIONINFO
  11. 批处理中for循环多个%
  12. Elasticsearch 2.3 (ELK)Geo_point绘图、日志Date时间获取实例
  13. 通过 python的 __call__ 函数与元类 实现单例模式
  14. webserver Etcd Cluster / CoreOS etcd / macOS etcd
  15. shell实现自动部署两台tomcat项目Ⅱ
  16. nginx简单介绍
  17. POJ 1458 最长公共子序列(dp)
  18. python 爬虫数据准换时间格式
  19. 神奇的 Block
  20. IT建设如何面对“短板”和“孤峰”?

热门文章

  1. 【心无旁骛】vuex-typescript-example
  2. PHP简单实现“相关文章推荐”功能的方法(此方法不是自创)
  3. 微信小程序之组件的集合(五)
  4. sudo apt-get update报错E: 部分索引文件下载失败。如果忽略它们,那将转而使用旧的索引文件。
  5. python 日记 day5 字典
  6. btree b+tree 的关系
  7. 【arc075f】AtCoder Regular Contest 075 F - Mirrored
  8. 修改mysql字段类型,修改字段名
  9. 转载 Python 安装setuptools和pip工具操作方法(必看)
  10. Python基础---三大推导式