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

vue-image-preview

v0.0.8

Published

本地图片预览组件

Downloads

20

Readme

vue-image-preview

本地图片预览组件

安装

npm install vue-image-preview

使用

VUE版本:1.x 必须在vue-cli生成的webpack模板环境中使用

<template>
  <image-preview :size="[640, 300]" file-size="1048576" :verify="verifyImage">
    <!--根节点必须是label-->
    <label>
      <input type="file" accept="image/jpeg,image/png,image/gif">
    </label>
  </image-preview>
</template>
<!--需要自定义图片选择控件的样式-->
<style>
  label {
  }
  label input {
    display: none;
  }
</style>
<script>
  // 注册组件
  import imagePreview from 'vue-image-preview'
  export default {
    components: {
      imagePreview
    },
    methods: {
      // 自定义图片预览的校验
      verifyImage (previewObj) {
        if (previewObj.width <= previewObj.height) return '请选择长方形图片'
      }
    },
    events: {
      onImagePreview (obj) {
        // 图片预览成功的事件
      },
      onImagePreviewError (errMsg) {
        // 图片预览失败的事件
      },
      onImagePreviewRemove (obj) {
        // 取消图片预览的事件
      }
    }
  }
</script>

image

图片选择控件的具体样式需要你自定义

Props

size(Array[Int, Int])

用于限制选择图片的像素尺寸

fileSize(Number/StringNumber)

用于限制选择图片的文件大小。单位:byte

verify(Function)

用于校验选择的图片。该函数如返回String数据,即代表校验不通过,该组件会将本次String数据作为出错提示dispatch出去,如返回Undefined(无返回数据),则代表校验通过。具体可参考上面示例

该函数的接收参数为PreviewObj

Events

onImagePreview

图片预览成功的事件。事件参数为PreviewObj

onImagePreviewError

图片预览失败的事件。事件参数errMsg可能为如下值:

  • 请使用尺寸为{width}*{height}的图片
  • 图片最大不能超过{fileSize}(MB/KB/B)
  • 图片格式不正确
  • 自定义校验方法返回的内容

onImagePreviewRemove

取消图片预览的事件。事件参数为PreviewObj

PreviewObj

{
  file: 当前图片的File对象,
  width: 当前图片的宽度,
  height: 当前图片的高度,
  dataUrl: 当前图片的DataUrl,
  imagePreview: 当前的vueImagePreview组件实例
}