axios发送对象,后端spring boot接收对象

做项目的时候,之前都是单个单个参数传递到spring boot后端,后端能直接以对象形式接收,但是前端这样一个个写太麻烦了,同学就写了这样的一个方法给我看,记录一下
(有些axios的post方法传到后端就接收不了,比如上面注释掉的部分直接传对象就接收不到,但是单个个传又没问题,下面没注释的传对象就能直接接收)

data数据

form: {
                companyId: '',
                address: '',
                eventType: '',
                occurredTime: '',
                description: '',
                reason1: '',
                reason2: '',
                reason3: '',
                measure: ''
            }

提交方法

onSubmit() {
            let data = this.form;
            console.log(data);
            // this.$axios
            //     .post(
            //         this.$GLOBAL.baseUrl + '/accidentAdd',
            //         this.$qs.stringify({
            //             // companyId: data.companyId,
            //             // address: data.address,
            //             // eventType: data.eventType,
            //             // occurredTime: data.occurredTime,
            //             // description: data.description,
            //             // reason1: data.reason1,
            //             // reason2: data.reason2,
            //             // reason3: data.reason3,
            //             // measure: data.measure
            //             accident: data
            //         })
            //     )
            //     .then((res) => {
            //         this.$message.success('提交成功!');
            //         bus.$emit('close_current_tags');
            //     });
            this.$axios({
                method: 'post',
                url: this.$GLOBAL.baseUrl + '/accidentAdd',
                data: data,
                transformRequest: [
                    (data) => {
                        return this.$qs.stringify(data); //使用Qs将请求参数序列化
                    }
                ]
            }).then((res) => {
                //逻辑代码
                console.log(res);
            });
        }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值