vue-imageview

A image view component for Vue2.0
1,609 33
Install
npm install vue-imageview
Latest Version:3.1.9
Vue:3
Last Updated:Feb 12, 2023
Links: GitHub  ·  npm
Maintainer: naice

vue preview image

A preview images component for Vue3

See The Demo

1、Usage with Vue3

npm install vue-imageview --save

2、Using as your need

]<template>
  <h1>点击图片进行预览</h1>
  <div id="imgBox">
    <img src="https://cdn.jsdelivr.net/gh/naihe138/myimages/img/20210523164644.jpg" alt="">
    <img src="https://cdn.jsdelivr.net/gh/naihe138/myimages/img/20210523164639.webp" alt="">
    <img src="https://cdn.jsdelivr.net/gh/naihe138/myimages/img/20210523164640.jpeg" alt="">
    <img src="https://cdn.jsdelivr.net/gh/naihe138/myimages/img/20210523164641.jpeg" alt="">
    <img src="https://cdn.jsdelivr.net/gh/naihe138/myimages/img/20210523164642.jpeg" alt="">
    <img src="https://cdn.jsdelivr.net/gh/naihe138/myimages/img/20210523164643.jpeg" alt="">
  </div>
  <ImagesView v-model:visible="show" :images="srcArr" :src="imgSrc" />
</template>

<script setup lang="ts">
  import ImagesView from './components/index';
  import { ref, onMounted } from 'vue'
  const show = ref(false)
  const srcArr = ref([])
  const imgSrc = ref('');
  const getData = (imgBox: HTMLDivElement) => {
    const imgs = imgBox.querySelectorAll('img');
    srcArr.value = Array.from(imgs).map((el) => el.src);
  }

  onMounted(() => {
    const imgBox: HTMLDivElement = document.querySelector('#imgBox');
    getData(imgBox);
    imgBox.addEventListener('click', (e: any) => {
      if(e.target.nodeName == 'IMG') {
        imgSrc.value = e.target.src;
        show.value = true
      }
    })
  });
</script>

Attributes

Attribute Description require Type Default
visible show/hide picker yes Boolean false
images images data for components [src1, src2] yes Array []
src show current images link yes String ''

Related Packages

markdown-to-jsx

A very fast and versatile markdown toolchain. AST, React, React Native, SolidJS,...

214,042,213 2,394
@scalar/use-toasts

display toasts in Vue

24,371,992 16,329
@scalar/use-codemirror

CodeMirror for Vue

21,770,238 16,329
@scalar/api-reference

Generate beautiful API references from OpenAPI documents

21,031,808 16,329
vaul-vue

Vaul Vue is an unstyled drawer component for Vue that can be used as a Dialog re...

19,162,483 497

Version History

Version Released Vue License
3.1.9 ^3.2.25
3.1.8 ^3.2.25
3.1.7 ^3.2.25
3.1.6 ^3.2.25
3.1.5 ^3.2.25