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);
                })