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

gkx-img-upload

v1.0.2

Published

基于vue的图片上传和预览插件

Downloads

3

Readme

vue-image-upload-preview

npm version

基于vue的图片上传和预览插件

该组件引用了 mint-uilrz

Install

npm install vue-image-upload-preview --save-dev

Usage

  • 引入图片上传和预览组件,可按需引入
  import {ImageUpload , ImagePreview} from 'vue-image-upload-preview'
  • 注册组件
  components:{
    'image-preview':ImagePreview,
    'image-upload':ImageUpload
  }
  • 使用组件
  <template>
    <div>
      <!-- 图片上传 -->
      <image-upload
       class="image-upload"
       ref='imgaeUpload'
       :url='http://XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX'
       :touch-size = 1
       :multiple = true
       :lrz-options = {width:1024}
       field-name = 'serverImgFile'
       :data = {}
       :max-count = 10
       @chooseImages='bindtap_chooseImages'
      />

      <!-- 图片预览 -->
      <image-preview
        style="z-index:200"
        :images="preImages"
        v-model="index"
        :numIsShow="true"
        :deleteIsShow="true"
        @delete="bindtap_delete"
      />

    </div>
  </template>
  • 绑定数据
    data() {
      return {
        index: -1,
        images: []
      }
    },

    computed:{
      preImages() {
        return this.images.map(v=>{return v.src});
      }
    }
  • 上传图片
  this.$refs.imgaeUpload.uploadImages(this.images)
  .then(res => {
    ...
  }).catch(res => {
    ...
  })
  • 自定义上传按钮样式
  .image_upload{  height: 60px; width: 60px;background: red}

Props

ImageUpload
  • url - String - 上传图片的路径;
  • field-name - Stirng - 上传图片的字段名;
  • multiple - Boolean - [default:false] - 是否支持图片多选;
  • lrz-options - Object - [default:{quality:0.7}] - 图片压缩选项,参考(https://github.com/think2011/localResizeIMG/wiki/2.-参数文档);
  • max-count - Number - [default:-1] - -1表示无限张;
  • chooseImages - Function - 选择图片回调;
    bindtap_chooseImages(e){
      /*
       * 选择成功 e是一个数组
       * e[0].file 图片文件对象,用于上传
       * e[0].src 图片base64,用于预览
       * e[0].compress 图片是否经过压缩
       */
       if(Array.isArray(e)){
          this.images = this.images.concat(e);
       }else {
          console.log(e);
       }
    }
ImagePreview
  • images - Array - [default:[]] - 预览图片的所有路径;
  • deleteIsShow - Boolean - [default:false] - 是否显示删除按钮;
  • numIsShow - Boolean - [default:false] - 是否显示数字;
  • chooseImages - Function - 选择图片回调;
    bindtap_delete(e){
      /*
       * e 当前显示的图片的下标(双向绑定index,可以忽略e)
       * this.images 存储选择图片传过来的对象
       * this.index 双向绑定当前显示的图片的下标
       * 下面是删除的例子
       */
      this.images = this.images.filter((v,i) => {
        return this.index!=i;
      })
    },

Notice

  • 使用方法仅供参考
  • /src/App.vue 有简单的例子 demo