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
相关产品推荐
相关产品推荐

