Code Monkey home page Code Monkey logo

wxpreview's Introduction

Vue preview plugin

一个Vue集成PhotoSwipe图片预览插件

Requirements

PhotoSwipe

Installation

npm i wxpreview -S

Usage

使用须知:

  • 插件目前仅支持vue2.0以上版本
  • img标签上的class不能去掉

如果你是使用vue-cli生成的项目,可能需要你修改webpack.base.conf.js文件中的loaders,添加一个loader。 原因:插件编写中使用了es6的语法,需要进行代码编译

{
    test: /vue-preview.src.*?js$/,
    loader: 'babel'
}

Install plugin

import VuePreview from 'vue-preview'
Vue.use(VuePreview)

Examples

<template>
  <img class="preview-img" v-for="(item, index) in list" :src="item.src" height="100" @click="$preview.open($even.target.parentNode,index, list)">
</template>

<script>
export default {
    data () {
      return {
        list: [{
          src: 'https://placekitten.com/600/400',
          w: 600,
          h: 400
        }, {
          src: 'https://placekitten.com/1200/900',
          w: 1200,
          h: 900
        }]
      }
    }
  }
</script>

Mothods

插件提供以下两个方法,vm代表组件实例

vm.$preview.open(el,index, list, options)

参数说明:

参数 说明 类型 必需
dom元素     在哪个元素下面找preview-img(默认为document)   obj   是
index 当前图片的索引值 Number
list 图片列表 Array
options 预览插件的配置选项(参考PhotoSwipe配置 Object

vm.$preview.close()

License

wxpreview's People

Contributors

ggwangxin avatar

Stargazers

sandisen avatar

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.