zoukankan      html  css  js  c++  java
  • vue 上传文件

    <input type="file" ref="files" style=" 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
                })
            }
        }

  • 相关阅读:
    python基础5之装饰器
    python基础4之递归、lambda、深浅copy
    python基础3之文件操作、字符编码解码、函数介绍
    python基础1之python介绍、安装、变量和字符编码、数据类型、输入输出、数据运算、循环
    python基础2之字符串、列表、字典、集合
    Mysql主从复制的实现
    LNMP一键安装脚本
    LNMP搭建(CentOS 6.3+Nginx 1.2.0+PHP 5.3.15(fpm)+ MySQL 5.5.35)
    整合apache+tomcat+keepalived实现高可用tomcat集群
    浅谈CSRF
  • 原文地址:https://www.cnblogs.com/king94Boy/p/11578376.html
Copyright © 2011-2022 走看看