今天给小伙伴们分享一个优秀的vue.js图片预览组件VuePhotoPreview。
vue-photo-preview 基于 PhotoSwipe 的 Vue 图片预览组件。超流畅的预览效果、完美支持pc及移动端适配。
安装
$ npm i vue-photo-preview -S
引入插件
// 在main.js中引入
import Vue from 'vue'
import photoPreview from 'vue-photo-preview'
import 'vue-photo-preview/dist/skin.css'
Vue.use(photoPreview)
// or
Vue.use(photoPreview, {
loop: false,
fullscreenEl: false, //是否全屏
arrowEl: false, //左右按钮
... //更多配置
})
也支持单独的引入js
<link rel="stylesheet" type="text/css" href="路径/dist/skin.css"/>
<script src="路径/dist/vue-photo-preview.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
var options= {
fullscreenEl: false, //是否全屏
arrowEl: false, //左右按钮
}
Vue.use(vuePhotoPreview,options)
new Vue({
el:'#app'
})
</script>
使用
在img标签添加 preview 属性,preview值相同即表示为同一组。
<template>
<div>
<img src="xxx.jpg" preview="0" preview-text="描述文字">
<!-- 分组 -->
<img src="xxx.jpg" preview="1" preview-text="描述文字">
<img src="xxx.jpg" preview="1" preview-text="描述文字">
<img src="xxx.jpg" preview="2" preview-text="描述文字">
<img src="xxx.jpg" preview="2" preview-text="描述文字">
<img src="xxx.jpg" large="xxx_3x.jpg" preview="2" preview-text="缩略图与大图模式">
</div>
</template>
<script>
export default {
data() {
return {}
},
}
</script>
# photoswipe插件文档
https://photoswipe.com/documentation/api.html
# demo地址
https://826327700.github.io/vue-photo-preview/demo/
# github地址
https://github.com/826327700/vue-photo-preview
ok,就分享到这里。
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。