HarmonyOS关于AXIOS动态传参数问题

在封装AXIOS时直接在params那里传个map怎么不行呢,只能挨个参数去传,挨个参数传的话就不太友好了,header那边已经可以正常动态传递。

let h=new RequestHeader() 
h.Authorization="eyJraWQiOiJFRxxxxxA" 
let map:Map<string,string>=new Map(); 
map.set('jsonStr',"{\"recruitId\":\"\",\"schoolId\":\"4961\"}"); 
map.set('secretStr','GdPx8KzUn0B6C+f+cLh5xxxxxIMbmh6vuveS/sX9ohoIc3bL/4gV1bO7FYgnf0pmR'); 
map.set('timeNote','1515340800'); 
map.set('osVersion','2'); 
axios<Info, AxiosResponse<Info>, null>({ 
  url: "https://example/index.html", 
  method: 'post', 
  headers:h, 
  params: map, 
}).then((res: AxiosResponse<Info>) => { 
  console.log("response======="+res.data.rt?.learnRecordUrl) 
  return res 
}).catch((err: AxiosError) => { 
  console.log("err====="+err.message) 
  return err 
})
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
HarmonyOS
2024-09-12 11:28:27
3061浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
put_get

类似router传参,Map数据不能直接传,可以先将map数据转为普通对象,然后进行传值,请参考以下demo:

import router from ‘@ohos.router’; 
let obj: Map<string, string> = new Map(); 
obj.set(‘name’, ‘ttt’); 
obj.set(‘age’, ‘18’); 
let jsonObject: Record<string, Object> = {}; 
obj.forEach((value, key) => { 
  if(key != undefined && value != undefined){ 
    jsonObject[key] = value; 
  } 
}); 
@Entry 
@Component 
struct Index { 
  @State message: string = ‘Hello World’; 
  build() { 
    Row() { 
      Column() { 
        Text(this.message) 
          .fontSize(50) 
          .fontWeight(FontWeight.Bold) 
        Button(‘Page’) 
        .onClick(()=>{ 
          console.info(JSON.stringify(jsonObject) ) 
          router.pushUrl({ 
            url: ‘pages/Page’, 
            params: jsonObject 
          }); 
        }) 
      } 
      .width(‘100%’) 
    } 
    .height(‘100%’) 
  } 
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
分享
微博
QQ
微信
回复
2024-09-12 17:28:52
相关问题
HarmonyOS 参数问题
930浏览 • 1回复 待解决
HarmonyOS 构造参数失败问题
715浏览 • 1回复 待解决
HarmonyOS 关于动态设置组件宽度的问题
1178浏览 • 1回复 待解决
关于动态创建的组件销毁问题
865浏览 • 1回复 待解决
HarmonyOS Web runJavaScript 如何参数
906浏览 • 1回复 待解决
HarmonyOS Checkbox如何动态
668浏览 • 1回复 待解决
关于JS http请求参数的传递问题
8440浏览 • 2回复 待解决
HarmonyOS axios请求问题
849浏览 • 1回复 待解决
关于 onArrange中获取到的参数问题
5646浏览 • 1回复 待解决
PreviewInfo url参数可以数组吗
315浏览 • 0回复 待解决
ArkTS 网络请求 接口动态
1335浏览 • 1回复 待解决
从ArkTs向Native复杂参数---List参数
1862浏览 • 1回复 待解决
HarmonyOS 路由页面接收回参数方式
2659浏览 • 1回复 待解决
HarmonyOS @build组件参数据没有刷新
787浏览 • 1回复 待解决
HarmonyOS axios下载文件问题
1023浏览 • 1回复 待解决
xargs命令中多个参数实例?
10455浏览 • 1回复 待解决
HarmonyOS 页面问题
1289浏览 • 1回复 待解决