commit | author | age
|
bf6fbe
|
1 |
<!-- 一个上传事例文件 --> |
L |
2 |
<template> |
|
3 |
<div> |
|
4 |
<el-button @click="upload">上传</el-button> |
|
5 |
</div> |
|
6 |
</template> |
|
7 |
|
|
8 |
<script> |
|
9 |
import Bus from '@/js/bus'; |
|
10 |
import $ from 'jquery' |
|
11 |
|
|
12 |
export default { |
|
13 |
components: {}, |
|
14 |
data() { |
|
15 |
return {} |
|
16 |
}, |
|
17 |
mounted() { |
|
18 |
// 文件选择后的回调 |
|
19 |
Bus.$on('fileAdded', () => { |
|
20 |
console.log('文件已选择') |
|
21 |
}); |
|
22 |
|
|
23 |
// 文件上传成功的回调 |
|
24 |
Bus.$on('fileSuccess', () => { |
|
25 |
console.log('文件上传成功') |
|
26 |
}); |
|
27 |
}, |
|
28 |
computed: {}, |
|
29 |
methods: { |
|
30 |
upload() { |
|
31 |
// 打开文件选择框 |
|
32 |
Bus.$emit('openUploader', { |
|
33 |
id: Math.ceil(Math.random()*10000) ,// 传入的参数 |
|
34 |
|
|
35 |
|
|
36 |
}) |
|
37 |
} |
|
38 |
}, |
|
39 |
destroyed() { |
|
40 |
Bus.$off('fileAdded'); |
|
41 |
Bus.$off('fileSuccess'); |
|
42 |
}, |
|
43 |
} |
|
44 |
</script> |
|
45 |
|
|
46 |
<style scoped lang="scss"> |
|
47 |
|
|
48 |
</style> |