Vue - 图片预览插件viewer.js的使用一

插件github

需求描述

对于图片列表咱们要进行查看(放大、缩小、旋转等)的时候,须要使用的插件css

示例

安装依赖

  • npm install viewerjs --save

在须要的页面引用

import Viewer from "viewerjs";
import "viewerjs/dist/viewer.css";
复制代码

HTML代码

<template>
  <div id="index">
    <ul>
      <li v-for="(item, index) in imgArr" :key="index">
        <img :src="item" />
      </li>
    </ul>
  </div>
</template>
复制代码

js代码

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

CSS代码

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

相关文章
相关标签/搜索