Giter Site home page Giter Site logo

mirari / v-viewer Goto Github PK

View Code? Open in Web Editor NEW
2.4K 15.0 287.0 25.08 MB

Image viewer component for vue, supports rotation, scale, zoom and so on, based on viewer.js

Home Page: https://mirari.cc/v-viewer/

License: MIT License

JavaScript 0.18% Vue 73.16% HTML 7.54% Shell 0.41% TypeScript 18.72%
vue viewer gallery picture img image

v-viewer's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

v-viewer's Issues

Not working with Nuxt.js out of the box, error: Unexpected token .

Problem

require("viewerjs/dist/viewer.css") inside compiled module crashes when running in Nuxt.js webpack environment (and possibly many others).

Steps to reproduce

This recreates full test environment completely from scratch:

mkdir viewtest
cd viewtest
yarn init .
yarn add nuxt v-viewer

create pages/index.vue:

<template>
<div v-viewer>
	<img src="https://lorempixel.com/600/400/">
	<img src="https://lorempixel.com/400/600/">
</div>
</template>

<script>
import Vue from 'vue'
import Viewer from 'v-viewer'
Vue.use(Viewer)

export default {}
</script>

Run server:

node_modules/.bin/nuxt

Open http://localhost:3000, the following error will be printed:

  nuxt:render Rendering url / +0ms
{ /Users/semenov/tmp/viewtest/node_modules/viewerjs/dist/viewer.css:11
.viewer-zoom-in::before,
^

SyntaxError: Unexpected token .
    at new Script (vm.js:51:7)
    at createScript (vm.js:136:10)
    at Object.runInThisContext (vm.js:197:10)
    at Module._compile (internal/modules/cjs/loader.js:618:28)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:665:10)
    at Module.load (internal/modules/cjs/loader.js:566:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:506:12)
    at Function.Module._load (internal/modules/cjs/loader.js:498:3)
    at Module.require (internal/modules/cjs/loader.js:598:17)
    at require (internal/modules/cjs/helpers.js:11:18)
    at webpackUniversalModuleDefinition (/Users/semenov/tmp/viewtest/node_modules/v-viewer/dist/v-viewer.js:3:49)
    at Object.<anonymous> (/Users/semenov/tmp/viewtest/node_modules/v-viewer/dist/v-viewer.js:10:3)
    at Module._compile (internal/modules/cjs/loader.js:654:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:665:10)
    at Module.load (internal/modules/cjs/loader.js:566:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:506:12) statusCode: 500, name: 'SyntaxError' }

Other notes

It is not as simple as CSS loader not being enabled. requiring css from the component script tag works fine:

<script>
require("viewerjs/dist/viewer.css")

export default {}
</script>
  • this works and will actually push CSS into the page.

页面会重复多个弹出框

bug效果如下:
gif。。。https://i.loli.net/2018/08/10/5b6ce6e4139b7.gif

下面是代码

<el-card class="box-card" v-viewer>
    <el-collapse v-model="logActive">
      <el-collapse-item name="log">
        <template slot="title">
          <div class="header">日志记录</div>
        </template>
        <el-table :data="formatLog" stripe style="width: 100%">
          <el-table-column prop="OperationTime" label="操作时间">
          </el-table-column>
          <el-table-column prop="CreateUser" label="操作人">
          </el-table-column>
          <el-table-column prop="Remark" label="操作内容">
            <template slot-scope="scope">
              <template v-if="scope.row.TaskType === 'Log'" >
                <span>{{ scope.row.Remark }}</span>
              </template>
              <template v-if="scope.row.TaskType === 'Image'" >
                <img style="max-height: 60px;" :src="scope.row.Remark.url" :title="scope.row.Remark.name" :alt="scope.row.Remark.name"/>
              </template>
              <template v-if="scope.row.TaskType === 'File'" >
                <a :href="scope.row.Remark.url" target="_blank">{{scope.row.Remark.name}}</a>
              </template>
            </template>
          </el-table-column>
        </el-table>
      </el-collapse-item>
    </el-collapse>
  </el-card>
import Viewer from 'v-viewer'
import Vue from 'vue'
Vue.use(Viewer)

Allowed formats

First of all, excellent work.
I would like to know if there is any way to show images and other types of files such as a PDF or Videos.
Greetings.

Getting a "Failed to resolve directive: viewer"?

I downloaded v-viewer.js into my project and registered it using Vue.use(VueViewer). I start getting the warning whenever I use "v-viewer" in my html. I'm assuming there are additional steps to successfully register the directive?

electron-vue使用报语法错误 vue直接使用没问题

image

Uncaught SyntaxError: Unexpected token .
at createScript (vm.js:74)
at Object.runInThisContext (vm.js:116)
at Module._compile (module.js:533)
at Object.Module._extensions..js (module.js:580)
at Module.load (module.js:503)
at tryModuleLoad (module.js:466)
at Function.Module._load (module.js:458)
at Module.require (module.js:513)
at require (internal/module.js:11)
at webpackUniversalModuleDefinition (E:

Capture click even on rendered v-viewer image

I am trying to capture a click event on the image element as it is rendered by v-viewer. I have tried adding template markup using scoped slots, and extending the whole component with no luck.

Ultimately I would like to record the X and Y position of the click in order to simulate 'dropping a pin' on the image.

Do you think it is possible?

Thank you for an awesome component!

希望能支持一下服务端渲染

目前在服务端渲染中v-viewer directive无法正常识别导致报错,希望能够支持下服务端渲染。例如提供延后处理的方法,把业务推迟到mounted之后。

viewer.view(index) not working

I've got a div element with multiple images inside.

If I do the below
var img = document.getElementById('imgdivid').$viewer; img.show(); img.view(index);

It always shows the first picture, while I want the index one to be loaded instead.

Is there any callback in show that I can use, so I can execute the view(index) once the viewer is shown?

Any idea why is that?

IE10,v-viewer.js 源码抛异常 Error in directive viewer bind hook: "TypeError: 对象不支持此操作"

[Vue warn]: Error in directive viewer bind hook: "TypeError: 对象不支持此操作"

(found in )
TypeError: 对象不支持此操作
{
[functions]: ,
description: "对象不支持此操作",
message: "对象不支持此操作",
name: "TypeError",
number: -2146827843,
stack: "TypeError: 对象不支持此操作
at c (http://localhost:8088/asset/js/lib/v-viewer-92fca2ef710c.js:53:29)
at bind (http://localhost:8088/asset/js/lib/v-viewer-92fca2ef710c.js:86:60)
at callHook$1 (http://localhost:8088/asset/js/lib/vue.min-f72e90dab59c.js:6280:7)
at _update (http://localhost:8088/asset/js/lib/vue.min-f72e90dab59c.js:6202:7)
at updateDirectives (http://localhost:8088/asset/js/lib/vue.min-f72e90dab59c.js:6183:5)
at invokeCreateHooks (http://localhost:8088/asset/js/lib/vue.min-f72e90dab59c.js:5685:7)
at createElm (http://localhost:8088/asset/js/lib/vue.min-f72e90dab59c.js:5573:11)
at createChildren (http://localhost:8088/asset/js/lib/vue.min-f72e90dab59c.js:5669:9)
at createElm (http://localhost:8088/asset/js/lib/vue.min-f72e90dab59c.js:5571:9)
at createChildren (http://localhost:8088/asset/js/lib/vue.min-f72e90dab59c.js:5669:9)"
}

open inline in a specific div

i want the image to open inline in a specific div so that i add more content by the side
how can i do that ? thanks

列表中循环多次指令,只能最后一个生效

当在列表中使用指令方式时,只有列表的最后一项可以显示出来,而其他的都报错,因为获取不到$viewer对象。

<template>
  <el-table
    :data="records"
    style="width: 100%"
    :border="true"
    :class="'mbaex-table'"
    :stripe="true"
  >
    <el-table-column
      prop="status"
      label="状态"
      width="125">
      <template slot-scope="scope">
        <div class="color-primary" v-if="scope.row.status == 3">
          等待确认
          <span class="inlin-block pt-15 pb-15 pr-10 pl-5 cursor-pointer" title="点击查看图片" @click="showImgViewer">查看图片</span>
          <div class="hidden viewer-box" v-viewer="{url: 'data-large', navbar: false, movable: false}">
            <img :data-large="scope.row.receiptUrl" alt="">
          </div>
        </div>
        <div class="color-primary" v-if="scope.row.status == 1">
          支付成功
          <span class="inlin-block pt-15 pb-15 pr-10 pl-5 cursor-pointer" title="点击查看图片" @click="showImgViewer">查看图片</span>
          <div class="hidden viewer-box" v-viewer="{url: 'data-large', navbar: false, movable: false}">
            <img :data-large="scope.row.receiptUrl" alt="">
          </div>
        </div>
      </template>
    </el-table-column>
  </el-table>
</template>
<script>
  export default {
    data(){
      records: [
        {
            "receiptUrl": "https://car2.autoimg.cn/cardfs/product/g2/M08/4C/52/1024x0_1_q87_autohomecar__wKgHGVttOOuAZF-3AAmEjM2FLPM352.jpg",
            "status": 1
        },
        {
            "status": 2
        },
        {
            "receiptUrl": "https://car2.autoimg.cn/cardfs/product/g2/M00/4C/52/1024x0_1_q87_autohomecar__wKgHGVttOOeAEBGPAApcgEw-noc081.jpg",
            "status": 1
        },
        {
            "receiptUrl": "https://gss3.bdstatic.com/7Po3dSag_xI4khGkpoWK1HF6hhy/baike/c0%3Dbaike180%2C5%2C5%2C180%2C60/sign=d49cfe51f703918fc3dc359830544df2/6159252dd42a283483209fba5bb5c9ea14cebff9.jpg",
            "status": 1
        }
      ]
    },
    methods: {
      // 点击"图片图标"显示大图
      showImgViewer(e){
        let event = e || window.event;
        this.$nextTick(() => {
          let target = event.currentTarget || event.target.parentElement,
            parent = target.parentElement;
            
          let viewer = parent.querySelector(".viewer-box").$viewer;
          console.log(parent.querySelector(".viewer-box"))
          console.log(viewer)
          viewer.show();
        });        
      }
    }
  }
</script>

在我的项目中,出现的问题就是只有最后一张图片能够点击,并显示出来,其他图片点击就报错

Component method not working!

<viewer :images="this.awardData.files">
          <img v-for="src in this.awardData.files" :src="'src'" :key="src">
        </viewer>

Hey, above is my code. I tried using component method. But nothing is shown in the browser.

Is that I should use directive method also or any of the methods(component, directives) is fine?

Bounds

Hi, Thank you for the great work.
I'd like to try to use the plugin for displaying examples but I need the option to keep image inside a container.
I mean when edges of a picture can't be moved inside a container
is there a way to set bounds to keep zoomed image inside a container?

Re render viewer when resize window

Hi,
Do you have any idea if I can re-render the viewer when I manipulate the window width. I've tried to re-assign the options with a dynamic minWidth param but it doesn't work.
I appreciate with some could help me out with this issue.
Regards,

Console logs for directive

Hi Mirari,

Console logs for directive are pretty annoying. If you really need them, is it possible to pass some value {verbose : true} through options that will show them, so that they are not showing by default?

Regards,
Marin

v0.3.x 升级 v1.x 直接乱

讲真, 给个升级 API 修改提醒啊. 如果不是 vue 版的问题, 那么也在文档说出 viewerjs 在接口做出变更的提醒啊...

可以修改全局默认配置吗?

我直接在main.js里面import 和 Vue.use后,我就可以在所有路由组件使用了.可是可以修改全局默认配置吗,这样就不需要再在每个使用的地方都写一遍options.Viewer.setDefaults(options)用这个会报错
errMsg:Uncaught TypeError: __WEBPACK_IMPORTED_MODULE_12_v_viewer___default.a.setDefaults is not a function

inline 模式时,配合输入框,v-viewer 重复渲染

操作输入框时,v-viewer 重复渲染

<template>
  <section>
    <div class="viewer-box">
      <viewer :images="[images]" :options="options">
        <img class="viewer-image" :src="images">
      </viewer>
    </div>
    <el-input v-model="inputValue"></el-input>
  </section>
</template>
<script>
  import Viewer from 'v-viewer';
  export default {
    components: {
      Catalog,
      XforceHeader
    },
    data() {
      return {
        inputValue: '',
        options: {
          'inline': true,
          'button': false,
          'navbar': false,
          'title': false,
          'toolbar': true,
          'tooltip': false,
          'movable': true,
          'zoomable': true,
          'rotatable': true,
          'scalable': false,
          'transition': true,
          'fullscreen': false,
          'keyboard': false,
          'url': 'data-source'
        },
        images: 'https://avatars2.githubusercontent.com/u/7300964?s=88&v=4'
      }
    }
  }
</script>
<style lang="scss">
  .viewer-box {
    width: 400px;
    height: 400px;
  }
</style>

viewer.css

import 'viewerjs/dist/viewer.css'
viewer.css 找不到哦

如何只去掉图片切换时候的动画

这个组件做得很棒,先给作者点个赞。
我在使用的过程中,感觉里面的动画过渡效果很好,比如旋转、缩放时候的动画,但是当切换图片列表上一张下一张的时候,那个从中间缩放出来的效果我不想要,但是我想保留其他的动画效果。
目前只找到一个transition属性来开关所有的动画效果,但是没有办法只去掉图片切换时候的动画。

想请教如何做到,谢谢!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.