axios中put的参数怎么传_axios的delete方法传递参数

1、axois介绍

直接看中文文档,点击跳转

2、踩坑点

一开始以为delete方法的传递参数和put post 应该差不多,就按照这个想法写,结果搞死没有把参数带到后端去,错误写法如下:

util.ajax.delete('api/space/app_delete', qs.stringify({

id: this.id

}), {headers: {'Content-Type': 'application/x-www-form-urlencoded;charset:UTF-8'}})

.then(response => {

this.loading = false;

if (response.data.code === this.GLOBAL.requestOk) {

this.$Message.success('项目删除成功!');

} else {

this.$Message.error(response.data.list.msg);

return false;

}

}).catch(error => {

this.$Message.error(error.message);

});

结果这样怎么都没法把id 这个参数传输给后端, 最后看了下axios的源码 发现这样写不对。。。贴出源码关键部分

request(config: AxiosRequestConfig): AxiosPromise

;get(url: string, config?: AxiosRequestConfig): AxiosPromise;

delete(url: string, config?: AxiosRequestConfig): AxiosPromise;

head(url: string, config?: AxiosRequestConfig): AxiosPromise;

post(url: string, data?: any, config?: AxiosRequestConfig): AxiosPromise;

put(url: string, data?: any, config?: AxiosRequestConfig): AxiosPromise;

patch(url: string, data?: any, config?: AxiosRequestConfig): AxiosPromise;

3、正确做法

发现delete的传递参数方式和put、post等不一样,第一个参数为url,这个没问题,第二个参数直接传递的是一个config ,那是不是可以这样传递参数呢?

util.ajax.delete('api/space/app_delete',

{

data: qs.stringify({

id: params.row.id})

}).then(response => {

if (response.data.code === this.GLOBAL.requestOk) {

that.tableData.splice(params.index, 1)

this.$Message.success('项目删除成功');

} else {

this.$Message.error(response.data.list);

}

this.$Modal.remove();

}).catch(error => {

this.$Message.error(error.message);

});

最后发现,上面的这样写可以将id这个参数传递给后端,这个坑了我将近1个小时,终于解决,做下记录

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值