Giter Site home page Giter Site logo

d2phap / vue-file-selector Goto Github PK

View Code? Open in Web Editor NEW
15.0 2.0 8.0 2.79 MB

File selector with validation that supports drag-n-drop for @vuejs

Home Page: https://imageglass.org/about

License: MIT License

Vue 40.78% JavaScript 43.95% TypeScript 6.56% SCSS 8.71%
vuejs vue-component file-selector drag-and-drop drag-drop file-upload vue-resource file-input selector-component filesystem

vue-file-selector's Introduction

Vue File selector for Vuejs 3

FOSSA Status

File selector with validation that supports drag-n-drop for Vuejs.

Vue File selector

Other open source projects

Install

Run the command

npm i vue-file-selector@latest

NPM package: https://www.npmjs.com/package/vue-file-selector

Github source: https://github.com/d2phap/vue-file-selector

Usage

Please see Demo project for full example.

Declare the plugin

// in main.ts

import { createApp } from 'vue';

// import FileSelector main css
import 'vue-file-selector/dist/main.css';

// import the FileSelector plugin
import FileSelector from 'vue-file-selector';


import App from './App.vue';

createApp(App)

  // then use it!
  .use(FileSelector)
  .mount('#app');

Use in Vue file

<template>
  <div>
    <FileSelector
      accept-extensions=".jpg,.svg"
      :multiple="true"
      :max-file-size="5 * 1024 * 1024"
      @validated="handleFilesValidated"
      @changed="handleFilesChanged">
      Select image files
    </FileSelector>
  </div>
</template>

<script lang="ts">
import { Options, Vue } from 'vue-class-component';
import { FsValidationResult } from 'vue-file-selector/dist';

@Options({})
export default class App extends Vue {
  handleFilesValidated(result: FsValidationResult, files: File[]) {
    console.log('Validation result: ' + result);
  },

  handleFilesChanged(files: File[]) {
    console.log('Selected files: ');
    console.table(files);
  },
}
</script>

Slots

Name Default Description
default Select Content of the Select button.
loader Loading... Content of loading state.
top (empty) Top section content, above the Select button.
bottom (empty) Bottom section content, below the Select button.

Props

Name Type Default Description
multiple boolean false Allow multiple files selected.
isLoading boolean false Show or hide the loading section (slot: loader).
acceptExtensions string (empty) List of file extensions accepted. Each extension separated by a comma (,). E.g. accept-extensions=".zip,.rar".
maxFileSize number NaN Maximum size in byte of every single file allowed. E.g. :max-file-size="2*1024*1024" (only the files that โ‰ค2 MB are allowed).
height number NaN The height of droppable section.
validateFn FsValidateFn () => true A custom validation function that returns boolean value.

Events

1. @validated

Occurs after the selected files validated.

Function(result: FsValidationResult, files: File[]): void
  • result: validation result,
  • files: list of files validated.

2. @changed

Occurs if the selected files pass validation.

Function(files: File[]): void
  • files: list of files validated.

Error codes

List of error codes returned after validation, see FsValidationResult.

Code Error description
EXTENSION_ERROR The selected files contain invalid extensions.
FILE_SIZE_ERROR The selected files size exceeded limit.
MULTIFILES_ERROR Multiple files selection is not allowed.

License

FOSSA Status

vue-file-selector's People

Contributors

d2phap avatar dependabot[bot] avatar fossabot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

vue-file-selector's Issues

File selector in Vue 3

Hello,

Is there a way I can use this component with my Vue 3 application ?

I used it many times in Vue 2 projects, but unfortunately I don't get it to work in Vue 3.

Thank you!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.