HarmonyOS 鸿蒙Next装完axios之后一用axios.get就报错?

发布于 1周前 作者 htzhanglong 来自 鸿蒙OS

HarmonyOS 鸿蒙Next装完axios之后一用axios.get就报错?

 我已经正确安装好axios了

import Axios from '@ohos/axios’<button style="position: absolute; padding: 4px 8px 0px; cursor: pointer; top: 8px; right: 8px; font-size: 14px;">复制</button>
 /**

  • 基于axios实现异步查询商铺
  • @returns */ getShopListByAxios():Promise<ShopInfo[]>{ return new Promise((resolve,reject)=>{ Axios.get( ${<span class="hljs-keyword"><span class="hljs-keyword">this</span></span>.baseURL}/shops, { params:{pageNo:this.pageNo,pageSize:3} } ).then((resp)=>{ resolve(resp.data) }).catch(error=>{ reject(‘失败’) })
})

}<button style="position: absolute; padding: 4px 8px 0px; cursor: pointer; top: 8px; right: 8px; font-size: 14px;">复制</button>

现在遇到的问题是我一写上“Axios.get”这样的字眼编辑器就会出现下面的错误:

cke_12055.png

[Compile Result]     at handleFullModuleFiles (D:\huawei\SDK\openharmony<span class=“hljs-number”>9\ets\build-tools\ets-loader\lib\gen_abc_plugin.js:1:13052)
[Compile Result]     at GenAbcPlugin.handleFinishModules (D:\huawei\SDK\openharmony<span class=“hljs-number”>9\ets\build-tools\ets-loader\lib\gen_abc_plugin.js:2:3272)
[Compile Result]     at Hook.eval [as callAsync] (eval at create (D:\huawei\SDK\openharmony<span class=“hljs-number”>9\ets\build-tools\ets-loader\node_modules\webpack\node_modules\tapable\lib\HookCodeFactory.js:33:10), <anonymous>:40:1)
[Compile Result]     at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (D:\huawei\SDK\openharmony\9\ets\build-tools\ets-loader\node_modules\webpack\node_modules\tapable\lib\Hook.js:18:14)
[Compile Result]     at Compilation.finish (D:\huawei\SDK\openharmony\9\ets\build-tools\ets-loader\node_modules\webpack\lib\Compilation.js:2714:28)
[Compile Result]     at D:\huawei\SDK\openharmony\9\ets\build-tools\ets-loader\node_modules\webpack\lib\Compiler.js:1182:19
[Compile Result] Compile error occurred. Fix it based on the above message.
<button style="position: absolute; padding: 4px 8px 0px; cursor: pointer; top: 8px; right: 8px; font-size: 14px;">复制</button>

1 回复

在 HarmonyOS(鸿蒙)开发中,使用 axios 或其他基于浏览器环境的 HTTP 客户端库(如 fetch)可能会遇到一些问题,因为 HarmonyOS 应用(尤其是基于HarmonyOS 2.0及以上版本的FA(Feature Ability)或Stage模型的应用)并非直接运行在传统的Web浏览器环境中。axios 和 fetch 是为浏览器环境设计的,它们依赖于浏览器提供的网络API,如 XMLHttpRequest 或 Fetch API。

回到顶部