1
1
# Vue File selector
2
- File selector component that supports drag-n-drop for @ vuejs
2
+ File selector component that supports drag-n-drop for Vuejs.
3
3
4
- ## Install
4
+ ## Install
5
5
Run the command
6
6
```
7
- npm i fluent-reveal-effect @latest
7
+ npm i vue-file-selector @latest
8
8
```
9
9
10
10
NPM package: https://www.npmjs.com/package/vue-file-selector
11
11
12
+ Github source: https://github.com/d2phap/vue-file-selector
13
+
12
14
## Usage
15
+ Please see [ Demo project] ( https://github.com/d2phap/vue-file-selector/tree/master/demo ) for full example.
13
16
14
- #### Declare the plugin
17
+ ### Declare the plugin
15
18
``` js
16
19
// import the library
17
20
import FileSelector from ' vue-file-selector' ;
@@ -24,13 +27,11 @@ Vue.use(FileSelector);
24
27
``` html
25
28
<template >
26
29
<div >
27
- My App.vue comp
28
-
29
30
<file-selector
30
- accept-extensions =" .zip "
31
+ accept-extensions =" .jpg "
31
32
:height =" 300"
32
- @validate = " validate "
33
- @change = " change "
33
+ @validated = " handleFilesValidated "
34
+ @changed = " handleFilesChanged "
34
35
>
35
36
hahahah
36
37
</file-selector >
@@ -41,15 +42,62 @@ Vue.use(FileSelector);
41
42
export default {
42
43
name: ' App' ,
43
44
methods: {
44
- validate (result , files ) {
45
+ handleFilesValidated (result , files ) {
45
46
console .log (' Validation result: ' + result);
46
47
},
47
48
48
- change (files ) {
49
- console .log (' Selected files: ' , files);
49
+ handleFilesChanged (files ) {
50
+ console .log (' Selected files: ' );
51
+ console .table (files);
50
52
},
51
53
},
52
54
};
53
55
</script >
54
56
```
55
57
58
+ ## Slots
59
+ | Name | Default | Description |
60
+ | -- | -- | -- |
61
+ | ` default ` | ` Select ` | Content of the ` Select ` button. |
62
+ | ` loader ` | ` Loading... ` | Content of loading state. |
63
+ | ` top ` | | Top section content, above the ` Select ` button. |
64
+ | ` bottom ` | | Bottom section content, below the ` Select ` button. |
65
+
66
+
67
+ ## Props
68
+ | Name | Type | Default | Description |
69
+ | -- | -- | -- | -- |
70
+ | ` multiple ` | ` Boolean ` | ` false ` | Allow multiple files selected. |
71
+ | ` is-loading ` | ` Boolean ` | ` false ` | Show or hide the loading section (slot: ` loader ` ). |
72
+ | ` accept-extensions ` | ` String ` | ` ` | List of file extensions accepted. Each extension separated by a comma (` , ` ). E.g. ` accept-extensions=".zip,.rar" ` . |
73
+ | ` max-file-size ` | ` 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). |
74
+ | ` height ` | ` Number ` | ` NaN ` | The height of droppable section. |
75
+ | ` validate-fn ` | ` Function -> Boolean ` | ` () => true ` | A custom validation function that returns boolean value. |
76
+
77
+
78
+ ## Events
79
+ ### 1. ` @validated `
80
+ Occurs after the selected files validated.
81
+ ``` js
82
+ Function (result: String | Boolean , files: FileList ): void
83
+ ```
84
+ - ` result ` : validation result,
85
+ + returns ` true ` if the file validation is valid, else
86
+ + returns ` false ` or [ Error codes] ( #error-codes ) .
87
+ - ` files ` : list of files validated.
88
+
89
+ ### 2. ` @changed `
90
+ Occurs if the selected files pass validation.
91
+ ``` js
92
+ Function (files: FileList ): void
93
+ ```
94
+ - ` files ` : list of files validated.
95
+
96
+
97
+ ## Error codes
98
+ List of error codes returned after validation.
99
+ | Code | Error description |
100
+ | -- | -- |
101
+ | ` EXTENSION_ERROR ` | The selected files contain invalid extensions. |
102
+ | ` FILE_SIZE_ERROR ` | The selected files size exceeded limit. |
103
+ | ` MULTIFILES_ERROR ` | Multiple files selection is not allowed. |
0 commit comments