vue2中使用viewer.js的實(shí)現(xiàn)示例
先展示下實(shí)現(xiàn)效果

簡(jiǎn)單的圖片放大縮小、切換上一張下一張、左右旋轉(zhuǎn)可使用ElementUi中的el-image組件,但像上下左右
鏡像翻轉(zhuǎn)el-image組件就無法滿足,因此我這里使用到了viewer.js。
1. 安裝插件
npm install v-viewer@1.7.4
2. main.js
import "viewerjs/dist/viewer.css"; import Viewer from "v-viewer"; Vue.use(Viewer);
3. 圖片查看器組件
<template>
<div class="pics-view" v-viewer="viewerOptions">
<div
class="pics-item"
v-for="item in picsList"
:key="item.title + item.url"
>
<h4 class="title" :title="item.title">{{ item.title }}</h4>
<img :src="item.url" :alt="item.title" class="preview-img" />
</div>
</div>
</template>
<script>
export default {
props: {
// 圖片列表(title、url)
picsList: {
type: Array,
default: () => [],
},
},
data() {
return {
// 配置viewer.js的參數(shù)
viewerOptions: {
navbar: true,
title: true,
toolbar: {
prev: true,
next: true,
zoomIn: true,
zoomOut: true,
rotateLeft: true,
rotateRight: true,
flipHorizontal: true,
flipVertical: true,
reset: true,
},
button: function () {
const container = document.createElement("div");
container.className = "viewer-toolbar-custom";
// 上一張按鈕
const prevBtn = document.createElement("button");
prevBtn.type = "button";
prevBtn.className = "viewer-button viewer-prev";
prevBtn.innerHTML = '<i class="el-icon-arrow-left"></i>';
prevBtn.title = "上一張";
container.appendChild(prevBtn);
// 下一張按鈕
const nextBtn = document.createElement("button");
nextBtn.type = "button";
nextBtn.className = "viewer-button viewer-next";
nextBtn.innerHTML = '<i class="el-icon-arrow-right"></i>';
nextBtn.title = "下一張";
container.appendChild(nextBtn);
return container;
},
initialized: function (viewer) {
// 綁定上一張事件
const prevBtn = viewer.element.querySelector(".viewer-prev");
prevBtn.addEventListener("click", () => viewer.prev());
// 綁定下一張事件
const nextBtn = viewer.element.querySelector(".viewer-next");
nextBtn.addEventListener("click", () => viewer.next());
},
},
};
},
};
</script>
<style scoped lang="scss">
.pics-view {
display: flex;
flex-wrap: wrap;
gap: 20px;
.pics-item {
display: flex;
flex-direction: column;
align-items: center;
width: 200px;
.title {
width: 100%;
padding: 4px;
background-color: #ccc;
color: #fff;
text-align: center;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.preview-img {
width: 100%;
height: 100px;
object-fit: contain;
cursor: pointer;
border: 1px solid #eee;
border-radius: 4px;
transition: all 0.3s;
border: 1px solid #ccc;
&:hover {
border-color: #409eff;
}
}
}
}
</style>到此這篇關(guān)于vue2中使用viewer.js的實(shí)現(xiàn)示例的文章就介紹到這了,更多相關(guān)vue2使用viewer.js內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- vue 獲取攝像頭拍照并旋轉(zhuǎn)、裁剪生成新的圖片功能實(shí)現(xiàn)
- vue3使用threejs實(shí)現(xiàn)3D卡片水平旋轉(zhuǎn)效果的示例代碼
- 拿來即用的vue旋轉(zhuǎn)木馬組件demo
- Vue2實(shí)現(xiàn)圖片的拖拽,縮放和旋轉(zhuǎn)效果的示例代碼
- 基于Vue3實(shí)現(xiàn)旋轉(zhuǎn)木馬動(dòng)畫效果
- vue3實(shí)現(xiàn)旋轉(zhuǎn)圖片驗(yàn)證
- vue實(shí)現(xiàn)旋轉(zhuǎn)木馬動(dòng)畫
- Vue組件實(shí)現(xiàn)旋轉(zhuǎn)木馬動(dòng)畫
- vue使用exif獲取圖片旋轉(zhuǎn),壓縮的示例代碼
- Vue實(shí)現(xiàn)按鈕旋轉(zhuǎn)和移動(dòng)位置的實(shí)例代碼
相關(guān)文章
Vue3中的ref為何要用.value進(jìn)行值的調(diào)用呢
這篇文章主要介紹了Vue3中的ref為何要用.value進(jìn)行值的調(diào)用,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-09-09
Vue項(xiàng)目如何設(shè)置反向代理和cookie設(shè)置問題
這篇文章主要介紹了Vue項(xiàng)目如何設(shè)置反向代理和cookie設(shè)置問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-04-04
Vue3中provide和inject數(shù)據(jù)修改規(guī)則
在Vue3中,通過inject接收到的數(shù)據(jù)是否可以直接修改,取決于provide提供的值的類型和響應(yīng)式處理方式,本文給大家介紹Vue3中provide和inject數(shù)據(jù)修改規(guī)則,感興趣的朋友一起看看吧2025-04-04
一文詳解Pinia和Vuex與兩個(gè)Vue狀態(tài)管理模式
這篇文章主要介紹了一文詳解Pinia和Vuex與兩個(gè)Vue狀態(tài)管理模式,Pinia和Vuex一樣都是是vue的全局狀態(tài)管理器。其實(shí)Pinia就是Vuex5,只不過為了尊重原作者的貢獻(xiàn)就沿用了這個(gè)看起來很甜的名字Pinia2022-08-08
Vue3中Element Plus Table(表格)點(diǎn)擊獲取對(duì)應(yīng)id方式
這篇文章主要介紹了Vue3中Element Plus Table(表格)點(diǎn)擊獲取對(duì)應(yīng)id方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-10-10

