项目作者: nullptru

项目描述 :
👀A vue component for previewing images
高级语言: Vue
项目地址: git://github.com/nullptru/vue-previewer.git
创建时间: 2019-07-06T16:22:44Z
项目社区:https://github.com/nullptru/vue-previewer

开源协议:MIT License

下载


vue-previewer

👀 A vue component for previewing images

Live Demo

>> Live Demo

Features

  • no other dependencies
  • support zoom-in, zoom-out, rotate, fullscreen operations
  • support image events such as select, close
  • support customer options
  • support key operation
  • support footer slot

Install

  1. // with yarn
  2. yarn add vue-image-previewer
  3. // with npm
  4. npm install vue-image-previewer

Usage

  1. import VuePreviewer from 'vue-image-previewer'
  2. // defalut install
  3. Vue.use(VuePreviewer);
  4. // install with global options
  5. Vue.use(VuePreviewer, {
  6. defaultWidth: '100px',
  7. defaultHeight: '75px',
  8. thumbnailStyle: {
  9. backgroundSize: 'cover'
  10. },
  11. keyMap: {
  12. zoomin: '+',
  13. zoomout: '-',
  14. rotate: 'r',
  15. prev: 'ArrowLeft',
  16. next: 'ArrowRight'
  17. }
  18. })

Example

  1. new Vue({
  2. el: '#app',
  3. components: { VuePreviewer },
  4. data() {
  5. return {
  6. imgs: [
  7. 'http://pic.lvmama.com/uploads/pc/place2/2016-09-14/9aab9bb7-2593-4ca6-8c5a-31355443aebc.jpg',
  8. 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQJQQM7xWSl3uRGecETNjaLl8_2wmAvlGpwyzX_Xs3RyZoTsM_j',
  9. "http://crawl.nosdn.127.net/d426f0175b974f7cce092a8f16d0ee09.jpg",
  10. "http://seopic.699pic.com/photo/50093/5337.jpg_wh1200.jpg"
  11. ]
  12. }
  13. },
  14. template: '<vue-previewer :images="imgs" :options="{}"></vue-previewer>'
  15. })

Props

Property Type Description Default
images Array[String/ImageOptions] Images for previewing required
options PreviewerOptions Extra options for configing component {}
mode “image”, “link” show image as link or image “image”
showFooter Boolean Footer slot true

ImageOptions

  1. {
  2. src: 'xxx.jpg', // origin image source
  3. thumbnailSrc: 'xxxThumbnail.jpg', // thumbnail source
  4. width: '100px', // thumbnail width
  5. height: '75px', // thumbnail height
  6. name: 'Image Test' // Image name which shows in footer
  7. }

PreviewerOptions

  1. // default options
  2. {
  3. defaultWidth: '100px', // thumbnail width, '100px' or '20%'
  4. defaultHeight: '75px', // thumbnailStyle height, '100px' or '20%'
  5. thumbnailStyle: { backgroundSize: 'cover' },
  6. keyMap: {
  7. zoomin: '+',
  8. zoomout: '-',
  9. rotate: 'r',
  10. prev: 'ArrowLeft',
  11. next: 'ArrowRight'
  12. }
  13. }

Events

Event Description Parameters
close Trigger when component is closed
select Trigger when select a image from list Selected image(ImageOptions)

slot

Name Parameters
footer Current ImageOptions

🤗 Please feel free to contribute a PR or make an issue

License

VuePreviewer is MIT Licensed.

Copyright (c) 2019 Geass