vue 上传文件


<input type="file" ref="files" style="width: 268px;" />
 
<el-button class="submitBtn" type="primary" @click="submitForm($event)">确认发送权益</el-button>
 
 methods: {
        submitForm() {
            let fileVal = this.$refs.files.value;
            if (fileVal == '' || fileVal == null || !fileVal) {
                this.$message.error('请选择您要上传的文件');
                return false
            }
            let file = this.$refs.files.files[0];
            let dataFile = new FormData();
            dataFile.append('file_upload', file)
            let config = {
                headers: { 'Content-Type': 'multipart/form-data', 'Authorization': this.$cookie.get('Authorization') }
            };
            const instance = this.$axios.create({
                withCredentials: true
            })
            instance.post('/admin/adminCoupon/importCoupon.json', dataFile, config).then(res => {
                const data = res.data;
                if (data.success) {
                    fileVal = ''; // 清空表单
                    this.$message.success('上传成功');
                    return false
                } else {
                    this.$message.error(data.message);
                    return false
                }

            }).catch(err => {
                this.$message.error('服务异常,请重试');
                return false
            })
        }
    }

 

 

 

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM