對於圖片列表咱們要進行查看(放大、縮小、旋轉等)的時候,須要使用的插件css
npm install viewerjs --save
import Viewer from "viewerjs";
import "viewerjs/dist/viewer.css";
複製代碼
<template>
<div id="index">
<ul>
<li v-for="(item, index) in imgArr" :key="index">
<img :src="item" />
</li>
</ul>
</div>
</template>
複製代碼
data() {
return {
imgArr: [
"blob:http://localhost:8080/b0356b99-9492-4395-a82e-2c3a0bb2da84",
"blob:http://localhost:8080/b0356b99-9492-4395-a82e-2c3a0bb2da84",
"blob:http://localhost:8080/b0356b99-9492-4395-a82e-2c3a0bb2da84",
"blob:http://localhost:8080/b0356b99-9492-4395-a82e-2c3a0bb2da84",
"blob:http://localhost:8080/b0356b99-9492-4395-a82e-2c3a0bb2da84"
]
};
},
mounted() {
const ViewerDom = document.getElementById("index");
const viewer = new Viewer(ViewerDom, {});
}
複製代碼
圖片地址改成本身的圖片地址git
li {
margin-right: 15px;
margin-bottom: 15px;
width: 25%;
height: 200px;
display: inline-block;
}
li:hover{
cursor: zoom-in;
}
img {
height: 100%;
width: 100%;
object-fit: cover;
}
複製代碼
點擊圖片便可實現效果。下篇介紹如何對上傳後臺返回的圖片作預覽展現的效果(有那麼一丟丟不同,期待喲)github