Harmony开发踩坑细节

  1. @ohos.data.preferences (用户首选项)存储到本地的数据,再次跑项目,数据为空
    DevEco-Studio 项目重载会删掉原有包,重新安装新包,会默认每次把之前的数据清除掉,需要修改IDE配置
    Edit Configurations -> Keep Application Data 勾选


    image.png
  2. @ohos.net.http(数据请求)
    POST 请求 HttpRequestOptions 内的Header 设置成为
    { 'Content-Type': 'application/x-www-form-urlencoded' }后,仍然需要自己将Map类型的参数以拼接的参数形式传入字符串(系统库咋不根据类型进行处理,非要翻了文档才发现这个坑)

    // 将Map转换为数组,然后遍历并进行URL编码及拼接
    let formData = Array.from(parameters).map(([key, value]) => {
      let encodedKey = encodeURIComponent(key);
      let encodedValue = encodeURIComponent(value);
      return `${encodedKey}=${encodedValue}`;
    }).join('&');
image.png
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容