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-element-upload-image

v1.1.0

Published

Downloads

7

Readme

基于 element-ui 的简单且强大的图片上传组件

MIT Licence npm size download

原插件地址

点击这里

介绍

vue-ele-upload-image 通过对 element-ui 的 upload 组件进一步封装, 使得图片上传更加容易, 具体特点如下:

  • 简单: 一个参数即可支持单张图片模式/多张图片模式/拖拽上传/裁剪上传
  • 实用: 普通模式/拖拽模式/裁剪模式图片列表表现形式一样
  • 未阉割原 upload 组件功能

效果图

效果图

安装

npm install vue-element-upload-image --save

使用

// 全局引入
import EleUploadImage from "vue-element-upload-image";
Vue.component(EleUploadImage.name, EleUploadImage);
// 局部引入
import ElementUploadImage from "vue-element-upload-image";
export default {
  components: {
    ElementUploadImage
  }
};

示例

<!-- 默认(单张, 点击上传) -->
<template>
  <element-upload-image
    action="https://jsonplaceholder.typicode.com/posts/"
    v-model="image"
    :responseFn="handleResponse"
  ></element-upload-image>
</template>
<script>
  export default {
    data() {
      return {
        image: ""
      };
    },
    methods: {
      handleResponse(response, file, fileList) {
        // 根据响应结果, 设置 URL
        return "https://xxx.xxx.com/image/" + response.id;
      }
    }
  };
</script>
<template>
  <!-- 多张(multiple) -->
  <element-upload-image
    multiple
    :responseFn="handleResponse"
    action="https://jsonplaceholder.typicode.com/posts/"
    v-model="images"
  ></element-upload-image>
</template>

<script>
  export default {
    data() {
      return {
        images: ""
      };
    },
    methods: {
      handleResponse(response, file, fileList) {
        // 根据响应结果, 设置 URL
        return "https://xxx.xxx.com/image/" + response.id;
      }
    }
  };
</script>
<!-- 拖拽上传(drag) -->
<element-upload-image
  drag
  :responseFn="handleResponse"
  action="https://jsonplaceholder.typicode.com/posts/"
  v-model="image"
></element-upload-image>
<!-- 拖拽上传(crop) -->
<element-upload-image
  crop
  :responseFn="handleResponse"
  action="https://jsonplaceholder.typicode.com/posts/"
  v-model="image"
></element-upload-image>

Props 参数

props: {
  // 值
  value: {
    type: [String, Array, Object]
  },
  // 响应处理函数
  responseFn: Function,
  // 是否剪裁
  crop: {
    type: Boolean,
    default: false
  },
  // 裁剪高度
  cropHeight: {
    type: Number
  },
  // 裁剪宽度
  cropWidth: {
    type: Number
  },
  // 图片显示大小
  size: {
    type: Number,
    default: 150
  },
  // 大小限制(MB)
  fileSize: {
    type: Number
  },
  // 是否显示提示
  isShowTip: {
    type: Boolean,
    default: true
  },
  // 弹窗标题
  title: String,
  // 图片懒加载
  lazy: {
    type: Boolean,
    default: false
  },
  // 文件类型, 例如['png', 'jpg', 'jpeg']
  fileType: {
    type: Array
  },
  // 缩略图后缀, 例如七牛云缩略图样式 (?imageView2/1/w/20/h/20)
  // 如果存在, 则列表显示是加缩略图后缀的, 弹窗不带缩略图后缀
  thumbSuffix: {
    type: String,
    default: ''
  },
  // 是否显示上传成功的提示
  isShowSuccessTip: {
    type: Boolean,
    default: true
  },
  // 上传地址 (同官网)
  action: {
    type: String,
    required: true
  },
  // 设置上传的请求头部(同官网)
  headers: Object,
  // 文件个数显示(同官网)
  limit: Number,
  // 是否启用拖拽上传 (同官网)
  drag: {
    type: Boolean,
    default: false
  },
  // 删除前的操作(同官网)
  beforeRemove: Function
  // 	支持发送 cookie 凭证信息 (同官网)
  withCredentials: {
    type: Boolean,
    default: false
  },
  // 是否支持多选文件 (同官网)
  multiple: {
    type: Boolean,
    default: false
  },
  // 上传时附带的额外参数(同官网)
  data: Object,
  // 上传的文件字段名 (同官网)
  name: {
    type: String,
    default: 'file'
  },
  // 覆盖默认的上传行为,可以自定义上传的实现 (同官网)
  httpRequest: Function,
  // 接受上传的文件类型(thumbnail-mode 模式下此参数无效)(同官网)
  accept: String
}

事件

| 事件名 | 说明 | | ------ | -------- | | error | 上传失败 |