首頁  >  文章  >  web前端  >  基於photoswipe實現的vue圖片預覽組件(程式碼)

基於photoswipe實現的vue圖片預覽組件(程式碼)

不言
不言原創
2018-09-15 16:06:124750瀏覽

這篇文章帶給大家的內容是關於vue圖片預覽外掛如何創造(程式碼),有一定的參考價值,有需要的朋友可以參考一下,希望對你有幫助。

vue-image-swipe

基於photoswipe實現的vue圖片預覽元件

安裝

1 第一步

npm instatll vue-image-swipe -D

2第二步

vue 入口檔案引入

import Vue from 'vue'
import VueImageSwipe from 'vue-image-swipe'
import 'vue-image-swipe/dist/vue-image-swipe.css'
Vue.use(VueImageSwipe)

使用

<template>
<div>
  hello world
  <div>
    <ul>
      <li
        :key="index"
        @click="preview(index)"
        v-for="(l, index) in images">
         <img :src="l" alt="">
      </li>
    </ul>
  </div>
</div>
</template>
<script>
export default {
  name: 'app',
  data() {
    return {
      images: [
        'http://oayhezji6.bkt.clouddn.com/preview1.jpg',
        'http://oayhezji6.bkt.clouddn.com/preview2.jpg',
        'http://oayhezji6.bkt.clouddn.com/preview3.jpg',
        'http://oayhezji6.bkt.clouddn.com/preview9.jpg',
        'http://oayhezji6.bkt.clouddn.com/preview10.jpg',
        'http://oayhezji6.bkt.clouddn.com/preview6.jpg'
      ]
    }
  },
  created() {
  },
  methods: {
    preview(index) {
      this.$imagePreview({
        images: this.images,
        index: index,
      })
    }
  }
}
</script>

methods

只揭露了一個方法this.$imagePreview ,並綁定到vue的原型上
使用

this.$imagePreview(options = {})

options有三個參數

##參數預設值說明images空數組圖片的url數組index0預覽圖片的索引值, 預設是0#defaultOpt{}設定項
defaultOpt 的設定項請參考photoswipe設定項,


注意:無法保證所有設定項都是可用的

列舉一些常用的設定

defaultOpt: {
  fullscreenEl: true,
  shareEl: false,
  arrowEl: true,
  preloaderEl: true,
  loop: false,
  bgOpacity: 0.85,
  showHideOpacity: true,
  errorMsg: '<p class="pswp__error-msg">图片加载失败</p>',
}
相關推薦:

#HTML選擇圖片並直接預覽實作程式碼

如何使用Vue2x實作圖片預覽外掛

以上是基於photoswipe實現的vue圖片預覽組件(程式碼)的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn