【发布时间】:2023-03-24 15:30:01
【问题描述】:
嗨,伙计们,我正在尝试构建一个音乐播放器应用程序,然后我收到一个错误,例如无法正确读取拆分未定义不知道发生了什么问题,请尝试修复我的错误
import axios from "axios";
export const selectRandomKey = () => {
const keys = process.env.REACT_APP_YouTube_Keys.split(""); //we are splitting the api keys to make an array
const random = Math.floor(Math.random() * Math.floor(keys.length)); //this will get a random number
return keys[random];
}
export default axios.create({
baseURL: "https://www.googleapis.com/youtube/v3",
params: {
part: "snippet",
videoCategoryId: "10",
type: "video",
key: selectRandomKey()
}
});
【问题讨论】:
-
process.env.REACT_APP_YouTube_Keys控制台并检查是否正在填充值 -
不建议在前端使用密钥。
标签: javascript reactjs api react-hooks