最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Vue2 中使用圖片查看器 v-viewer的方法

 更新時間:2024年12月02日 10:11:04   作者:碼嘍的自我修養(yǎng)  
文章介紹了v-viewer插件,它是一個用于Vue的圖像查看器組件,基于viewer.js插件,可以通過npm安裝,支持指令形式和Vue組件形式的用法,并提供了豐富的配置選項(xiàng)和事件監(jiān)聽,感興趣的朋友跟隨小編一起看看吧

先看效果:

插件簡介

基于 viewer.js 插件,用于 Vue 的圖像查看器組件

官網(wǎng)地址:v-viewer

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

下載安裝

通過 npm 安裝:

npm install v-viewer

GitHub 下載地址:https://github.com/mirari/v-viewer

UMD 用法

Browser:

<link href="viewerjs/viewer.css" rel="external nofollow"  rel="stylesheet">
<script src="vue/vue.js"></script>
<script src="viewerjs/viewer.js"></script>
<script src="viewerjs/v-viewer.js"></script>
<!-- 指令形式 -->
<div class="images" v-viewer>
  <img src="1.jpg">
  <img src="2.jpg">
</div>
<!-- 組件形式 -->
<viewer :images="images">
  <img v-for="src in images" :src="src" :key="src">
</viewer>
<script>
  Vue.use(VueViewer.default)
</script>

CommonJS: 

var VueViewer = require('VueViewer');

AMD: 

require(['VueViewer'], function (VueViewer) {});

 Vue 指令形式用法

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

可以傳入 options 配置項(xiàng):v-viewer="{inline: true}"

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

<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>

Vue 組件形式用法

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

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

監(jiān)聽 inited 事件來獲取 viewer 實(shí)例,或者也可以用 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>

 插件配置項(xiàng)

其它詳細(xì)配置項(xiàng)請參考 viewer.js 的詳細(xì)說明:Viewer.js – 強(qiáng)大的JS/jQuery圖片查看器_dowebok

1、name:String,默認(rèn)值為 viewer

為了避免重名沖突,可以添加 name 配置項(xiàng),代碼引入如下:

<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>

2、defaultOptions:Object,默認(rèn)值為 undefined

在初始化時需要修改 viewer.js 的全局默認(rèn)配置項(xiàng),代碼引入如下:

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

在任何時候修改全局默認(rèn)配置項(xiàng),代碼如下: 

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

到此這篇關(guān)于Vue2 中使用圖片查看器 v-viewer的方法的文章就介紹到這了,更多相關(guān)Vue2 v-viewer使用內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Vue 實(shí)例事件簡單示例

    Vue 實(shí)例事件簡單示例

    這篇文章主要介紹了Vue 實(shí)例事件,結(jié)合簡單示例形勢分析了vue.js事件響應(yīng)與頁面元素相關(guān)操作技巧,需要的朋友可以參考下
    2019-09-09
  • vue2 el-table行懸停時彈出提示信息el-popover的實(shí)現(xiàn)

    vue2 el-table行懸停時彈出提示信息el-popover的實(shí)現(xiàn)

    本文主要介紹了vue2 el-table行懸停時彈出提示信息el-popover的實(shí)現(xiàn),用到了cell-mouse-enter、cell-mouse-leave兩個事件,具有一定的參考價值,感興趣的可以了解一下
    2024-01-01
  • Vue3多組件的N種編寫方式

    Vue3多組件的N種編寫方式

    Vue 本身以及周邊生態(tài)在設(shè)計語法糖上幾乎沒讓我失望過,包括本次亮相的 Vue Vine,它的出現(xiàn)引起了我對 Vue3 組件編寫方式的好奇,以及哪一種方式更接近「最佳實(shí)踐」?下面讓我來為大家一一道來
    2024-07-07
  • ElementUI實(shí)現(xiàn)在下拉列表里面進(jìn)行搜索功能詳解

    ElementUI實(shí)現(xiàn)在下拉列表里面進(jìn)行搜索功能詳解

    有時候需要用到下拉列表全選和搜索,下面這篇文章主要給大家介紹了關(guān)于ElementUI實(shí)現(xiàn)在下拉列表里面進(jìn)行搜索功能的相關(guān)資料,文中通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2023-04-04
  • vue使用swiper.js重疊輪播組建樣式

    vue使用swiper.js重疊輪播組建樣式

    這篇文章主要為大家詳細(xì)介紹了vue使用swiper.js重疊輪播組建樣式,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2019-11-11
  • vue實(shí)現(xiàn)pc端拍照上傳功能

    vue實(shí)現(xiàn)pc端拍照上傳功能

    這篇文章主要為大家詳細(xì)介紹了vue實(shí)現(xiàn)pc端拍照上傳功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-09-09
  • Vue 中 createElement 使用實(shí)例詳解

    Vue 中 createElement 使用實(shí)例詳解

    Vue 提供了createElement 來創(chuàng)建虛擬dom,方便我們來函數(shù)化的方式來定義復(fù)雜的組件結(jié)構(gòu),這篇文章主要介紹了Vue 中 createElement 使用詳解,需要的朋友可以參考下
    2022-10-10
  • vue單頁面應(yīng)用打開新窗口顯示跳轉(zhuǎn)頁面的實(shí)例

    vue單頁面應(yīng)用打開新窗口顯示跳轉(zhuǎn)頁面的實(shí)例

    今天小編就為大家分享一篇vue單頁面應(yīng)用打開新窗口顯示跳轉(zhuǎn)頁面的實(shí)例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-09-09
  • vue使用H5的audio標(biāo)簽問題

    vue使用H5的audio標(biāo)簽問題

    這篇文章主要介紹了vue使用H5的audio標(biāo)簽問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-12-12
  • vue-cli中的babel配置文件.babelrc實(shí)例詳解

    vue-cli中的babel配置文件.babelrc實(shí)例詳解

    Babel是一個廣泛使用的轉(zhuǎn)碼器,可以將ES6代碼轉(zhuǎn)為ES5代碼,從而在現(xiàn)有環(huán)境執(zhí)行。本文介紹vue-cli腳手架工具根目錄的babelrc配置文件,感興趣的朋友一起看看吧
    2018-02-02

最新評論

绥宁县| 鹿邑县| 鸡泽县| 临海市| 涡阳县| 温州市| 巫山县| 正宁县| 饶河县| 和政县| 新乐市| 东明县| 鱼台县| 滦平县| 湖南省| 双桥区| 长宁区| 贡山| 门头沟区| 定安县| 永丰县| 砀山县| 蒙阴县| 板桥市| 大厂| 宁南县| 仁寿县| 九寨沟县| 金川县| 壤塘县| 山阴县| 环江| 梧州市| 竹北市| 河池市| 汉源县| 汝城县| 南靖县| 兴文县| 阜南县| 连江县|