vue中axios params
时间: 2023-08-29 12:11:33 浏览: 164
vue项目中axios使用详解
5星 · 资源好评率100%
在Vue中使用axios发送请求时,可以使用params选项来传递参数。params是将参数添加到URL的请求字符串中,主要用于GET请求。示例代码如下:
```javascript
axios.get('/user', {
params: {
ID: 12345
}
})
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});
```
另外,在后台接收参数时,需要注意使用@RequestParam注解来接收单个数值,例如字符串或整数等。此时,前端应该使用params来传递参数。示例代码如下:
```javascript
export const startOsp = param => {
let temp = {}
temp.strId = param.strId
temp.userCode = param.userCode
temp.password = param.password
return axios.request({
url: '/方法名',
method: 'post',
data: param.dsmResponseReq,
params: temp
})
}
```
需要注意的是,params是用于GET请求,而data是用于POST请求,它们在axios的配置选项中具有不同的用途。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [vue中axios传参数组问题(data和params区别)](https://blog.csdn.net/weixin_43482333/article/details/126091577)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *2* [vue中axios.request发送请求中data与params的区别](https://blog.csdn.net/qq_37634156/article/details/116743852)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *3* [Vue 中axios配置实例详解](https://download.csdn.net/download/weixin_38735790/13607822)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 33.333333333333336%"]
[ .reference_list ]
阅读全文