欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Vue圖片瀏覽組件v-viewer用法分析【支持旋轉(zhuǎn)、縮放、翻轉(zhuǎn)等操作】

 更新時間:2019年11月04日 10:57:46   作者:蒼青浪  
這篇文章主要介紹了Vue圖片瀏覽組件v-viewer用法,結(jié)合實例形式分析了v-viewer的基本功能與使用方法,包括旋轉(zhuǎn)、縮放、翻轉(zhuǎn)等操作技巧,需要的朋友可以參考下

本文實例講述了Vue圖片瀏覽組件v-viewer用法。分享給大家供大家參考,具體如下:

v-viewer

用于圖片瀏覽的Vue組件,支持旋轉(zhuǎn)、縮放、翻轉(zhuǎn)等操作,基于viewer.js。

從0.x遷移

你需要做的唯一改動就是手動引入樣式文件:

import 'viewerjs/dist/viewer.css'

安裝

使用npm命令安裝

npm install v-viewer

使用

引入v-viewer及必需的css樣式,并使用Vue.use()注冊插件,之后即可使用。

<template>
 <div id="app">
  <!-- directive -->
  <div class="images" v-viewer>
   <img src="1.jpg">
   <img src="2.jpg">
   ...
  </div>
  <!-- component -->
  <viewer :images="images">
   <img v-for="src in images" :src="src" :key="src">
  </viewer>
 </div>
</template>
<script>
 import 'viewerjs/dist/viewer.css'
 import Viewer from 'v-viewer'
 import Vue from 'vue'
 Vue.use(Viewer)
 export default {
  data() {
   images: ['1.jpg', '2.jpg']
  }
 }
</script>

以指令形式使用

只需要將v-viewer指令添加到任意元素即可,該元素下的所有img元素都會被viewer自動處理。

你可以像這樣傳入配置項: v-viewer="{inline: true}"

如果有必要,可以先用選擇器查找到目標(biāo)元素,然后可以用el.$viewer來獲取viewer實例。

<template>
 <div id="app">
  <div class="images" v-viewer="{movable: false}">
   <img v-for="src in images" :src="src" :key="src">
  </div>
  <button type="button" @click="show">Show</button>
 </div>
</template>
<script>
 import 'viewerjs/dist/viewer.css'
 import Viewer from 'v-viewer'
 import Vue from 'vue'
 Vue.use(Viewer)
 export default {
  data() {
   images: ['1.jpg', '2.jpg']
  },
  methods: {
   show () {
    const viewer = this.$el.querySelector('.images').$viewer
    viewer.show()
   }
  }
 }
</script>

指令修飾器

static

添加修飾器后,viewer的創(chuàng)建只會在元素綁定指令時執(zhí)行一次。

如果你確定元素內(nèi)的圖片不會再發(fā)生變化,使用它可以避免不必要的重建動作。

<div class="images" v-viewer.static="{inline: true}">
 <img v-for="src in images" :src="src" :key="src">
</div>

以組件形式使用

你也可以單獨引入全屏組件并局部注冊它。

使用作用域插槽來定制你的圖片展示方式。

監(jiān)聽inited事件來獲取viewer實例,或者也可以用this.refs.xxx.$viewer這種方法。

<template>
 <div id="app">
  <viewer :options="options" :images="images"
      @inited="inited"
      class="viewer" ref="viewer"
  >
   <template scope="scope">
    <img v-for="src in scope.images" :src="src" :key="src">
    {{scope.options}}
   </template>
  </viewer>
  <button type="button" @click="show">Show</button>
 </div>
</template>
<script>
 import 'viewerjs/dist/viewer.css'
 import Viewer from "v-viewer/src/component.vue"
 export default {
  components: {
   Viewer
  },
  data() {
   images: ['1.jpg', '2.jpg']
  },
  methods: {
   inited (viewer) {
    this.$viewer = viewer
   },
   show () {
    this.$viewer.show()
   }
  }
 }
</script>

配置項 & 方法

請參考viewer.js .

插件配置項

name

  • Type: String
  • Default: viewer

如果你需要避免重名沖突,可以像這樣引入:

<template>
 <div id="app">
  <div class="images" v-vuer="{movable: false}">
   <img v-for="src in images" :src="src" :key="src">
  </div>
  <button type="button" @click="show">Show</button>
 </div>
</template>
<script>
 import 'viewerjs/dist/viewer.css'
 import Vuer from 'v-viewer'
 import Vue from 'vue'
 Vue.use(Vuer, {name: 'vuer'})
 export default {
  data() {
   images: ['1.jpg', '2.jpg']
  },
  methods: {
   show () {
    const vuer = this.$el.querySelector('.images').$vuer
    vuer.show()
   }
  }
 }
</script>

defaultOptions

  • Type: Object
  • Default: undefined

如果你需要修改viewer.js的全局默認(rèn)配置項,可以像這樣引入:

import Viewer from 'v-viewer'
import Vue from 'vue'
Vue.use(Viewer, {
 defaultOptions: {
  zIndex: 9999
 }
})

你還可以在任何時候像這樣修改全局默認(rèn)配置項:

import Viewer from 'v-viewer'
import Vue from 'vue'
Vue.use(Viewer)
Viewer.setDefaults({
 zIndexInline: 2017
})

希望本文所述對大家vue.js程序設(shè)計有所幫助。

相關(guān)文章

  • vue2.x element-ui實現(xiàn)pc端購物車頁面demo

    vue2.x element-ui實現(xiàn)pc端購物車頁面demo

    這篇文章主要為大家介紹了vue2.x element-ui實現(xiàn)pc端購物車頁面demo,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2023-06-06
  • 詳解Vue自定義指令及使用

    詳解Vue自定義指令及使用

    這篇文章主要介紹了Vue自定義指令及使用,對Vue感興趣的同學(xué),可以參考下
    2021-05-05
  • 關(guān)于對keep-alive的理解,使用場景以及存在的問題解讀

    關(guān)于對keep-alive的理解,使用場景以及存在的問題解讀

    這篇文章主要介紹了關(guān)于對keep-alive的理解,使用場景以及存在的問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2024-05-05
  • vue中v-model雙向綁定input輸入框問題

    vue中v-model雙向綁定input輸入框問題

    這篇文章主要介紹了vue中v-model雙向綁定input輸入框問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2023-04-04
  • vue3時間插件之Moment.js使用教程

    vue3時間插件之Moment.js使用教程

    這篇文章主要給大家介紹了關(guān)于vue3時間插件之Moment.js使用的相關(guān)資料,需要的朋友可以參考下
    2023-09-09
  • vue v-model的用法解析

    vue v-model的用法解析

    這篇文章主要介紹了v-model的基本用法解析,幫助大家更好的理解和學(xué)習(xí)vue v-model的使用方法,感興趣的朋友可以了解下
    2020-10-10
  • vue實現(xiàn)通訊錄功能

    vue實現(xiàn)通訊錄功能

    這篇文章主要為大家詳細(xì)介紹了vue實現(xiàn)通訊錄功能,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-07-07
  • vue+elementUI實現(xiàn)簡單日歷功能

    vue+elementUI實現(xiàn)簡單日歷功能

    這篇文章主要為大家詳細(xì)介紹了vue+elementUI實現(xiàn)簡單日歷功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2020-09-09
  • vue3父子傳值實現(xiàn)彈框功能的示例詳解

    vue3父子傳值實現(xiàn)彈框功能的示例詳解

    這篇文章主要為大家詳細(xì)介紹了vue3如何利用父子傳值實現(xiàn)彈框功能,文中的示例代碼講解詳細(xì),具有一定的借鑒價值,感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下
    2023-12-12
  • 詳解如何使用vue和electron開發(fā)一個桌面應(yīng)用

    詳解如何使用vue和electron開發(fā)一個桌面應(yīng)用

    這篇文章主要為大家介紹了詳解如何使用vue和electron開發(fā)一個桌面應(yīng)用,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2023-03-03

最新評論