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