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-easy-uploader

v1.0.6

Published

一个基于Vue的上传插件

Downloads

13

Readme

vue-easy-uploader

一个基于Vue的移动端多文件上传插件,支持常见图片的上传。

特性

  • 多文件上传
  • 上传图片预览
  • 上传状态监测
  • 删除指定图片
  • 清空图片
  • 重新上传

安装

npm i vue-easy-uploader --save

使用

在入口文件main.js中加入以下代码:

import Vue from 'vue'
import Vuex from 'vuex'
import uploader from 'vue-easy-uploader'

let store = new Vuex.Store({})
Vue.use(uploader, store)

插件内部设置了状态管理,因此需要vuex的支持。

在Vue组件中使用

<uploader
	url="http://..."
></uploader>

参数说明

url: 上传接口路径

需要与后端约定上传格式,使用表单提交方式,后端需获取input[type='file']name属性,默认为name="imgFiles[0]"name="imgFiles[1]" ...数组序号从0递增。

上传成功时返回的数据如下:

示例代码

<template>
  <div>
    <uploader
      url="http://..."
    ></uploader>
    <div class="btn" @click="upload">
      上传
    </div>
  </div>
</template>

<script>
import { mapState } from 'vuex'
export default {
  data () {
    return {
      imgs: []
    }
  },
  computed: {
    ...mapState({
      imgStatus: state => state.imgstore.img_status,
      imgPaths: state => state.imgstore.img_paths
    })
  },
  methods: {
    upload () {
      this.$store.commit('set_img_status', 'uploading')
    },
    submit () {
      let values = []
      for (let key of this.imgPaths) {
        values.push(key)
      }
      this.imgs = values
      console.log(this.imgs)
    }
  },
  watch: {
    imgStatus () {
      if (this.imgStatus === 'finished') {
        this.submit()
      }
    }
  },
  destoryed () {
    this.imgs = []
  }
}
</script>

<style scoped lang="less">
.btn {
  width: 100%;
  height: 3em;
  background-color: green;
  color: #fff;
  display: flex;
  justify-content: center;
  align-items: center;
}
</style>

状态管理

状态管理存储在state.imgstore中,包括:

state.imgstore.img_upload_cache # 上传文件缓存
state.imgstore.img_status # 上传状态,包括 ready selected uploading finished
state.imgstore.img_paths # 上传后的路径反馈数组(数据结构为Set集合)

img_status

整个上传过程都通过img_status判断,包括以下几个状态:

ready # 上传开始前的准备状态
selected # 已选择上传文件
uploading # 开始上传
finished # 上传完毕

开始上传

this.$store.commit('set_img_status', 'uploading')

只需要改变状态管理中的img_statusuploading即可。

上传完成

methods: {
  submit () {
    // some code
  }
}
computed: {
  ...mapState({
    imgStatus: state => state.imgstore.img_status
  })
},
watch: {
  imgStatus () {
    if (this.imgStatus === 'finished') {
      this.submit()
    }
  }
}

监视state.imgstore.img_status,当状态变为finished时,执行文件上传完成后的回调。

详细的示例可访问本项目的 GitHub地址