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-upload-photo

v0.0.7

Published

Vue 图片上传组件(base64)

Downloads

11

Readme

Vue 图片上传组件(支持 Vue2、Vue3)

组件保存的是图片的 base64 码,如果有 BUG,请提 issues

在线 demo

文档

|字段|类型|描述|默认值|值类型|示例| |-|-|-|-|-|-| |type|属性值|组件显示模式 0.图片预览 1.图片列表 2.带有上传按钮的图片预览|0|Number| |disabled|属性值|禁用组件|false|Boolean| |access|属性值|组件允许上传的图片类型|image/*|String| |files|属性值|组件图片数据|[]|Array|v-model="files" files:[{ url: 'xxx', name: 'xxx.jpg'}]| |label|属性值|上传按钮|'点击上传'|String| |limit|属性值|限制上传的图片数量,0 为不限制|0|Number| |max-size|属性值|允许上传图片的最大尺寸,单位字节|null|Number| |multiple|属性值|是否允许多选|false|Boolean| |compress|属性值|是否开启压缩|false|Boolean| |quality|属性值|压缩质量|0.8|Number| |before-read|属性值|读取文件前的钩子函数|null|Function,返回值为 true 则继续读取图片,为 false 则不进行任何操作| |after-read|属性值|读取文件后的钩子函数|null|Function,参数为读取后的图片| |before-remove|属性值|移除文件前的钩子函数|null|Function,参数为要预览的图片索引值 index 和图片 file,返回值为 true 则删除图片,为 false 则不进行任何操作| |oversize|事件|图片大小超过 max-size 时触发|null|Function,参数为超过尺寸大小的图片| |exceed|事件|图片超出限制个数时触发|null|Function| |preview|事件|点击图片上的 + 号触发预览事件|null|Function,参数为要预览的图片索引值 index 和图片 file|

使用

Vue2

在单文件组件中引用

npm i vue-upload-photo
import Vue from 'vue'
import VueUploadImgs from 'vue-upload-photo'

Vue.use(VueUploadImgs)
<template>
    <div>
        <VueUploadImgs 
            multiple
            compress
            :before-read="beforeRead"
            :after-read="afterRead"
            :before-remove="beforeRemove"
            :limit="limit"
            :type="type"
            @preview="preview"
            @exceed="exceed"
            @oversize="oversize"
            v-model="files"
        >
        </VueUploadImgs>
    </div>
</template>

在HTML文件中直接引用

<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<!-- 开发环境 -->
<script src="https://cdn.jsdelivr.net/npm/vue-upload-photo/dist/VueUploadImgs.iife.js"></script>
<!-- 生产环境 -->
<script src="https://cdn.jsdelivr.net/npm/vue-upload-photo/dist/VueUploadImgs.iife.min.js"></script>
<div id="app">
    <vue-upload-photo 
        multiple
        compress
        :before-read="beforeRead"
        :after-read="afterRead"
        :before-remove="beforeRemove"
        :limit="limit"
        :type="type"
        @preview="preview"
        @exceed="exceed"
        @oversize="oversize"
        v-model="files"
    >
    </vue-upload-photo>
</div>

Vue3

在单文件组件中引用

npm i vue-upload-photo
import { createApp } from 'vue'
import VueUploadImgs from 'vue-upload-photo/dist/vue3/VueUploadImgs.esm'
import App from './App.vue'

createApp(App)
    .component('VueUploadImgs', VueUploadImgs)
    .mount('#app')
<template>
    <div>
        <VueUploadImgs 
            multiple
            compress
            :before-read="beforeRead"   
            :after-read="afterRead"
            :before-remove="beforeRemove"
            :limit="limit"
            :type="type"
            @preview="preview"
            @exceed="exceed"
            @oversize="oversize"
            v-model="files"
        >
        </VueUploadImgs>
    </div>
</template>

在HTML文件中直接引用

<script src="https://unpkg.com/vue@next"></script>
<!-- 开发环境 -->
<script src="https://cdn.jsdelivr.net/npm/vue-upload-photo/dist/vue3/VueUploadImgs.iife.js"></script>
<!-- 生产环境 -->
<script src="https://cdn.jsdelivr.net/npm/vue-upload-photo/dist/vue3/VueUploadImgs.iife.min.js"></script>
<div id="app">
    <vue-upload-photo 
        multiple
        compress
        :before-read="beforeRead"
        :after-read="afterRead"
        :before-remove="beforeRemove"
        :limit="limit"
        :type="type"
        @preview="preview"
        @exceed="exceed"
        @oversize="oversize"
        v-model="files"
    >
    </vue-upload-photo>
</div>

<script>
const app = Vue.createApp({
    components: {
        VueUploadImgs: VueUploadImgs.default,
    },
    // ...
})

app.mount('#app')
</script>