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

Vue.js 2.6项目转TypeScript时Axios调用报TS2554错误求助

解决Axios.get的TypeScript参数错误

错误原因:Axios的get方法仅接受1-2个参数,第一个是请求URL,第二个是配置对象,你当前传入了3个参数(URL、params单独对象、withCredentials配置对象),不符合TypeScript的类型校验规则。

修正后的getPartnerReferences方法代码:

async getPartnerReferences(params: any) {
  if (!params) return;
  // 将params和withCredentials合并到同一个配置对象中
  const { data } = await axios.get(`${path}/GroupAccountService/PartnerReferences`, { 
    params: params,
    withCredentials: true
  });
  return data.data;
}

也可以用对象展开语法简化写法:

async getPartnerReferences(params: any) {
  if (!params) return;
  const { data } = await axios.get(`${path}/GroupAccountService/PartnerReferences`, { 
    params,
    withCredentials: true
  });
  return data.data;
}

调整后,Axios的调用参数符合官方定义,TypeScript的参数数量错误即可消除。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.02 06:42:46