我正在使用 axios 从 API 获取数据:
const fetchData = async () => {
try {
const response = await axios.get(API_ENDPOINT)
const res = await response.data;
console.log(res);
setMovie(res.results);
} catch (error) {
console.log(error);
}
}
我使用 vite 作为捆绑器,因此可以通过以下方式访问创建的环境变量:
const API_ENDPOINT = import.meta.env.VITE_URL;
TypeError: Cannot read properties of undefined (reading 'protocol')
我在使用fetch
尝试调试,通过编写一些测试来查看错误是否发生在
const response = await axios.get(API_ENDPOINT)
之前。
解决问题的另一个方法是建立数据库。
“获取主项目时出错:TypeError:无法读取未定义的属性(读取‘协议’)”
提前致谢