实现一个vue的图片预览插件
2024-09-01 21:05:07
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
来源:https://segmentfault.com/a/1190000016409430
最新文章
- WinForm设置控件焦点focus
- shell中三种引号的用法
- SQL Server 2008 R2 未能加载文件或程序集Microsoft.SqlServer.Sqm...
- juqery 实现商城循环倒计时
- Java线程操作方法
- DAO接口及实现类
- 努力学习 HTML5 (4)&mdash;&mdash; 浏览器对语义元素的支持情况
- DB2中OLAP函数使用示例
- [转载]GMM的EM算法实现
- OSVERSIONINFO
- 批处理中for循环多个%
- Elasticsearch 2.3 (ELK)Geo_point绘图、日志Date时间获取实例
- 通过 python的 __call__ 函数与元类 实现单例模式
- webserver Etcd Cluster / CoreOS etcd / macOS etcd
- shell实现自动部署两台tomcat项目Ⅱ
- nginx简单介绍
- POJ 1458 最长公共子序列(dp)
- python 爬虫数据准换时间格式
- 神奇的 Block
- IT建设如何面对“短板”和“孤峰”?
热门文章
- 【心无旁骛】vuex-typescript-example
- PHP简单实现“相关文章推荐”功能的方法(此方法不是自创)
- 微信小程序之组件的集合(五)
- sudo apt-get update报错E: 部分索引文件下载失败。如果忽略它们,那将转而使用旧的索引文件。
- python 日记 day5 字典
- btree b+tree 的关系
- 【arc075f】AtCoder Regular Contest 075 F - Mirrored
- 修改mysql字段类型,修改字段名
- 转载 Python 安装setuptools和pip工具操作方法(必看)
- Python基础---三大推导式