網站首頁 編程語言 正文
我在本地開發了一個分頁的接口
這里 我設置的是 form-data 參數類型
要的是個表單類型的數據 然后呢 我按傳統PC端的方式處理了數據
<template>
<view class = "box">
<view class="management"></view>
</view>
</template>
<script>
export default {
data() {
return {
page: 1,
pageSize: 3
}
},
mounted() {
let data = new FormData();
console.log(this.page);
data.append("page", this.page);
data.append("pageSize", this.pageSize);
console.log(data);
uni.request({
url: '/books/page',
method: 'GET',
data: data,
header: {
"content-type": "multipart/form-data",
},
success: (res) => {
console.log(res.data);
},
fail: (err) => {
console.log(err);
},
})
}
}
</script>
<style scoped>
.box{
height: 50vh;
width: 100vw;
}
.management{
width: 100vw;
height: 33%;
border-bottom: 1px solid black;
}
</style>
但是這樣 運行起項目
他連請求都沒法出去
渲染 uni中使用FormData是有問題的
我直接將代碼改成
<template>
<view class = "box">
<view class="management"></view>
</view>
</template>
<script>
export default {
data() {
return {
page: 1,
pageSize: 3
}
},
mounted() {
uni.request({
url: '/books/page',
method: 'GET',
data: {
page: this.page,
pageSize: this.pageSize
},
header: {
"content-type": "application/x-www-form-urlencoded",
},
success: (res) => {
console.log(res.data);
},
fail: (err) => {
console.log(err);
},
})
}
}
</script>
<style scoped>
.box{
height: 50vh;
width: 100vw;
}
.management{
width: 100vw;
height: 33%;
border-bottom: 1px solid black;
}
</style>
我們數據就還是給JSON data
只需要在 header 中加上 “content-type”: “application/x-www-form-urlencoded”,
我們運行代碼 他就成一個表單類型的數據了
數據也成功的請求回來了
原文鏈接:https://blog.csdn.net/weixin_45966674/article/details/131446045
- 上一篇:沒有了
- 下一篇:沒有了
相關推薦
- 2022-11-02 react父組件更改props子組件無法刷新原因及解決方法_React
- 2022-12-23 Mariadb數據庫主從復制同步配置過程實例_mariadb
- 2023-01-14 C++應用Eigen庫對應實現matlab中部分函數問題_C 語言
- 2022-12-21 PyGame實現初始化導入所有模塊方法詳解_python
- 2022-06-18 C#實現無損壓縮圖片代碼示例_C#教程
- 2022-02-11 ES6的Promise用法詳解_基礎知識
- 2022-12-09 C++使用標準庫實現事件和委托以及信號和槽機制_C 語言
- 2022-08-25 .net加載失敗的程序集實現重新加載_實用技巧
- 欄目分類
-
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支