npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

photo-preview-for-vue

v0.1.6

Published

一款超简单的图片预览工具

Downloads

5

Readme

photo-preview-for-vue

一款超简单的图片预览工具

特点

没有任何配置,没做任何兼容。如果要兼容低版本浏览器,自行在项目中配置Babel。

使用

npm下载插件

npm install photo-preview-for-vue

main.js引入模块,并加载模块。注意了,必须想使用Vue.use加载才能正常使用,十分依赖vue。

import photoPreviewForVue from 'photo-preview-for-vue'
Vue.use(photoPreviewForVue)

第一种使用方式

在img标签中使用

<!-- 在img标签添加preview属性 preview值相同即表示为同一组 -->
<img src="xxx.jpg" preview="0" title="描述文字">

第二种使用方式

使用函数形式

// 引入模块
import { photoPreview } from 'photo-preview-for-vue'

// 打开预览
const closePreview = photoPreview({
  // 图片列表
  lists: [{
    src: 'xxx.jpg',
    title: '描述文字'
  }],
  // 预览的索引
  current: 0,
  // 预览关闭的回调
  closeCallback: () => {},
  // 预览切换土拍你的回调 data是图片的当前数据,current 是索引
  changeCallback: ({data, current}) => {}
})

// 通过返回值来关闭预览
closePreview()

除了使用photoPreview的返回值关闭预览,还可以引入closePreview来关闭预览

// 引入模块
import { photoPreview, closePreview } from 'photo-preview-for-vue'

// 打开预览
photoPreview({
  // 图片列表
  lists: [{
    src: 'xxx.jpg',
    title: '描述文字'
  }],
  // 预览的索引
  current: 0,
  // 预览关闭的回调
  closeCallback: () => {},
  // 预览切换土拍你的回调 data是图片的当前数据,current 是索引
  changeCallback: ({data, current}) => {}
})

// 关闭预览
closePreview()

第三种使用方式

使用预览面板组件

<template>
  <div>
    <button @click="previewForComponent">打开</button>
    <photo-perview v-model="visible" :image-lists="list" :default-current="current" @change="previewChange" />
  </div>
</template>

<script>
import { PhotoPerview } from 'photo-preview-for-vue'
export default {
  name: 'App',
  components: {
    PhotoPerview
  },
  data() {
    return {
      list: [
        {
          src: require('./assets/xxx.jpg'),
          title: '描述'
        }
      ],
      current: 0,
      visible: false
    }
  },
  methods: {
    previewForComponent() {
      this.visible = true
    },
    previewChange({ current }) {
      this.current = current
    }
  }
}
</script>

注意事项

如果是使用第一种方式,当图片是动态加载时,请在图片加载后使用$previewRefresh来重新加载预览。

<img src="xxx.jpg" preview="0" title="描述文字" @load="$previewRefresh">

由于预览是个单例,在打开新的预览时,是会先关闭旧的预览。