You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

GlideApps中使用axios报axios(...).then is not a function如何解决

问题原因

你使用的是AMD规范的异步require加载模式,这种模式下require([模块名], 回调函数)的返回值不是你要导入的模块实例,模块只会作为参数传入回调函数内部。你之前把require的返回值赋值给axios变量,拿到的根本不是axios实例,调用它自然会报「不是函数」的错误。

修正方案

将所有axios相关逻辑都移入require的回调函数内,同时为了适配Glide自定义函数的异步返回要求,把整体逻辑包装为Promise返回即可:

window.function = function(request_url) {
  return new Promise((resolve, reject) => {
    require(['axios'], function (axios) {
      const config = {
        method: 'get',
        url: request_url,
        headers: {}
      };
      axios(config)
        .then(response => resolve(JSON.stringify(response.data)))
        .catch(error => {
          console.log(error);
          reject(error);
        });
    });
  });
}
更稳定的替代方案(无需依赖axios)

如果仍存在模块加载问题,Glide运行环境本身支持原生fetchAPI,可以直接用它替代axios,不需要额外加载第三方模块:

window.function = async function(request_url) {
  try {
    const response = await fetch(request_url);
    const data = await response.json();
    return JSON.stringify(data);
  } catch (error) {
    console.log(error);
    throw error;
  }
}

内容的提问来源于stack exchange,提问作者Sam44

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.23 22:45:06