1
- # vue-simple-uploader [ ![ NPM Version] [ npm-image ]] [ npm-url ] [ ![ NPM Downloads] [ downloads-image ]] [ downloads-url ] [ ![ juejin likes] [ juejin-image ]] ( juejin-url )
1
+ # vue-simple-uploader [ ![ NPM Version] [ npm-image ]] [ npm-url ] [ ![ NPM Downloads] [ downloads-image ]] [ downloads-url ] [ ![ juejin likes] [ juejin-image ]] [ juejin-url ]
2
2
3
3
> A Vue.js upload component powered by [ simple-uploader.js] ( https://github.com/simple-uploader/Uploader )
4
4
26
26
## Install
27
27
28
28
``` bash
29
- npm install vue-simple-uploader --save
29
+ npm install vue-simple-uploader@next --save
30
30
```
31
31
32
32
## Notes
@@ -40,18 +40,13 @@ npm install vue-simple-uploader --save
40
40
### init
41
41
42
42
``` js
43
- import Vue from ' vue'
43
+ import { createApp } from ' vue'
44
44
import uploader from ' vue-simple-uploader'
45
45
import App from ' ./App.vue'
46
46
47
- Vue .use (uploader)
48
-
49
- /* eslint-disable no-new */
50
- new Vue ({
51
- render (createElement ) {
52
- return createElement (App)
53
- }
54
- }).$mount (' #app' )
47
+ const app = createApp (App)
48
+ app .use (uploader)
49
+ app .mount (' #app' )
55
50
```
56
51
57
52
### App.vue
@@ -71,17 +66,42 @@ new Vue({
71
66
</template>
72
67
73
68
<script>
69
+ import { nextTick, ref, onMounted } from 'vue'
74
70
export default {
75
- data () {
71
+ setup () {
72
+ const uploader = ref(null)
73
+ const options = {
74
+ target: '//localhost:3000/upload', // '//jsonplaceholder.typicode.com/posts/',
75
+ testChunks: false
76
+ }
77
+ const attrs = {
78
+ accept: 'image/*'
79
+ }
80
+ const statusText = {
81
+ success: 'success',
82
+ error: 'error',
83
+ uploading: 'uploading',
84
+ paused: 'paused',
85
+ waiting: 'waiting'
86
+ }
87
+ const complete = () => {
88
+ console.log('complete', arguments)
89
+ }
90
+ const fileComplete = () => {
91
+ console.log('file complete', arguments)
92
+ }
93
+ onMounted(() => {
94
+ nextTick(() => {
95
+ window.uploader = uploader.value.uploader
96
+ })
97
+ })
76
98
return {
77
- options: {
78
- // https://github.com/simple-uploader/Uploader/tree/develop/samples/Node.js
79
- target: '//localhost:3000/upload',
80
- testChunks: false
81
- },
82
- attrs: {
83
- accept: 'image/*'
84
- }
99
+ uploader,
100
+ options,
101
+ attrs,
102
+ statusText,
103
+ complete,
104
+ fileComplete
85
105
}
86
106
}
87
107
}
@@ -181,7 +201,7 @@ Root component.
181
201
}
182
202
if (status === ' success' || status === ' error' ) {
183
203
// only use response when status is success or error
184
-
204
+
185
205
// eg:
186
206
// return response data ?
187
207
return response .data
@@ -224,6 +244,15 @@ See [simple-uploader.js uploader/events](https://github.com/simple-uploader/Uplo
224
244
You can get it like this:
225
245
226
246
``` js
247
+ // Composition API
248
+ const uploader = ref (null )
249
+ // there will be an uploader attribute on the uploader component, which points to the Uploader instance
250
+ const uploaderInstance = uploader .value .uploader
251
+ // now you can call all uploader methods
252
+ // https://github.com/simple-uploader/Uploader#methods
253
+ uploaderInstance .cancel ()
254
+
255
+ // Options API
227
256
const uploaderInstance = this .$refs .uploader .uploader
228
257
// now you can call all uploader methods
229
258
// https://github.com/simple-uploader/Uploader#methods
@@ -387,14 +416,12 @@ npm run dev
387
416
388
417
# build for production with minification
389
418
npm run build
390
-
391
- # build for production and view the bundle analyzer report
392
- npm run build --report
393
419
```
394
420
395
421
[ npm-image ] : https://img.shields.io/npm/v/vue-simple-uploader.svg?style=flat
396
422
[ npm-url ] : https://npmjs.org/package/vue-simple-uploader
397
423
[ downloads-image ] : https://img.shields.io/npm/dm/vue-simple-uploader.svg?style=flat
398
424
[ downloads-url ] : https://npmjs.org/package/vue-simple-uploader
399
- [ juejin-image ] : https://badge.juejin.im/entry/599dad0ff265da248b04d7b8/likes .svg?style=flat
425
+ [ juejin-image ] : https://img.shields.io/badge/Jue%20Jin-446Likes-blue .svg
400
426
[ juejin-url ] : https://juejin.im/entry/599dad0ff265da248b04d7b8/detail
427
+
0 commit comments