我正在构建一个反应 js 网站,我必须在其中调用货币转换器 API。在本地(在本地主机上)服务时调用该 API 可以正常工作,但是一旦我将它部署到 Netlify,它就无法工作。
ConvertCurrency = async (from, to, amount) => {
let endpoint = 'xxxxxx';
let access_key = "xxxxxxxxxxxx";
const url = 'http://data.fixer.io/api/' + endpoint + '?access_key=' + access_key + '&from=' + from + '&to=' + to + '&amount=' + amount;
try {
const res = await Axios.get(url)
const rate = Math.round(((res.data.info.rate* 100) / 100)).toFixed(2)
return rate;
} catch (err) {
console.log(err)
}
return -1;
}
这是我正在捕获的错误(在 try{}catch(){} 异常中)。
Error: Network Error
at e.exports (createError.js:17)
at XMLHttpRequest.p.onerror (xhr.js:83)
任何帮助表示赞赏。
谢谢