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

silence-file-upload

v1.0.2

Published

文件上传组件

Downloads

8

Readme

默认上传行为

安装
npm i silence-file-upload
引入
import { createApp } from "vue";
import SilenceFileUpload from "silence-file-upload";
import "silence-file-upload/style.css";

const app = createApp();
app.use(SilenceFileUpload);
使用
使用默认上传行为
<template>
    <file-upload v-model="fileList" action="/api">
        <template #trigger>
            <el-button type="primary">上传文件</el-button>
        </template>
        <template #tip>
            文件大小不超过 500M
        </template>
    </file-upload>
</template>


<script lang="ts" setup>
    import type { Files } from "silence-file-upload";

    const fileList = ref<Files[]>([
        { fileName: "xxxxx", filePath: "" },
        { fileName: "xxxxx", filePath: "" }
    ]);
</script>
自定义上传行为
<template
    <file-upload v-model="fileList_" :http-request="httpRequest" />
</template>

<script lang="ts" setup>
    import { type Ref, ref } from "vue";
    import type { Files } from "silence-file-upload";
    
    const fileList_ = ref<Files[]>([
        { fileName: "xxx.js", filePath: "" },
        { fileName: "yyy.css", filePath: "" }
    ]);
    function httpRequest(fileList: Ref<Files[]>, index: number, file: File) {
        const formData = new FormData();
        formData.append("file", file, file.name);
        request({
            url: "/",
            method: "post",
            data: formData,
            onUploadProgress: function (ev: ProgressEvent) {
                const progress = ev.loaded / ev.total * 100;
                fileList.value[index].progress = progress;
                if (progress === 100) fileList.value[index].status = "success";
            }
        }).then(res => {
            if (res.code === 200) {
                fileList.value[index].status = "success";
                fileList_.value.push({
                    fileName: fileList.value[index].fileName,
                    filePath: fileList.value[index].filePath
                });
            }
        }).catch(() => {
            fileList.value[index].status = "error";
        })
    }
</script>

想要显示进度条和上传状态需要手动更新 Files.progressFiles.status

属性

| 属性名 | 说明 | 类型 | 可选值 | 默认值 | |-------------|----------------|---------------------------|-----|----| | v-model | 绑定值 | Files[] | —— | [] | | multiple | 是否允许多选 | boolean | true/false | true | | maxFileSize | 允许上传的文件最大限制(M) | number | —— | 500 | | action | 文件上传地址 | string | —— | —— | | headers | 请求头 | { [key: string]: string } | —— | {} |

事件

| 事件名 | 说明 | 回调参数 | |----|-----------|-----------------| | onSuccess | 文件上传后提供服务器返回信息 | (res: any, index: number) => void | | httpRequest | 自定义上传行为 | (fileList: Ref<Files[]>, index: number, file: File) => any |