zoukankan      html  css  js  c++  java
  • vue使用axios调用api接口 ---- content-type设置

    POST提交数据的三种请求方式写法

    1、Content-Type: application/json

    默认请求方式,在不设置Content-Type情况下默认为application/json请求方式

    2、Content-Type: multipart/form-data

    //表单上传
                    var form = new FormData();
                    form.append("file", this.fileObj);
                    form.append("customName", this.packfrom.customName);
                    form.append("version", this.packfrom.version);
                    form.append("deviceTypeId", this.packfrom.deviceTypeId);
                    form.append("comment", this.packfrom.comment);
                    axios({
                        method: 'post',
                        url: `${this.$APIURL}/upgradePackage/uploadFiles`,
                        headers: {
                            'Content-Type': 'multipart/form-data'
                        },
                        data:form
                    })
                    .then(response => {
                        const { data } = response                
                        if(data.code=="0")
                        {
                            console.log(data);
                            this.showpackdiafrom = false;
                            this.showdpackmanager();         
                            this.$message({
                                message: '添加成功!',
                                type: 'success'
                            });    
                            this.packfrom={}; 
                            this.fileobj="";
                            this.fileList=[];   
                            this.fileSizeIsSatisfy=false;
                        }
                        else
                        {
                            this.$message.error(data.msg);
                        }
                    }).catch(error => {
                        this.$message.error(error);
                    })

    3、Content-Type: application/x-www-form-urlencoded

    var params = {
                        pageIndex : that.packnowpage,
                        customName : that.packsearchinfo,
                    };
                    that.$axios
                    .post(`${this.$APIURL}/upgradePackage/list`,qs.stringify(params),{headers:{'Content-Type':'application/x-www-form-urlencoded'}})
                    .then(response => {
                        const { data } = response                
                        if(data.code=="0")
                        {
                            console.log(data);
                            //赋值
                            that.packData = data.data.list;
                            that.packnowpage = data.data.pageNum;
                            that.packcountpage = data.data.pages;                  
                        }
                        else
                        {
                            this.$message.error(data.msg);
                        }
                    }).catch(error => {
                        this.$message.error(error);
                    })
  • 相关阅读:
    codeforces 616B Dinner with Emma
    codeforces 616A Comparing Two Long Integers
    codeforces 615C Running Track
    codeforces 612C Replace To Make Regular Bracket Sequence
    codeforces 612B HDD is Outdated Technology
    重写父类中的成员属性
    子类继承父类
    访问修饰符
    方法的参数
    实例化类
  • 原文地址:https://www.cnblogs.com/JoeYD/p/13665191.html
Copyright © 2011-2022 走看看