简体   繁体   English

当我将 3 个 API 密钥添加到 .env 文件中时,一个 api 在控制台上的 React.js 中不起作用?

[英]When I added 3 API keys into .env file then one api does not work in React.js on console?

REACT_APP_API_KEY = xxxxxxxxxxxxxxxxxxxxx
REACT_APP_TEMPLATE_ID = xxxxxxxxxxxxxxxxx
REACT_APP_SERVICE_ID = xxxxxxxxxxxxxxxxxx
  • I put all the above code into.env file of react.js project我把上面所有的代码都放到了react.js项目的.env文件中

const API_KEY = process.env.REACT_APP_API_KEY;
const SERVICE_KEY = process.env.REACT_APP_SERVICE_ID;
const TEMPLATE_ID = process.env.REACT_APP_TEMPLATE_ID;
console.log(API_KEY,SERVICE_KEY,TEMPLATE_ID)
const Contact = () => {....

-When I console I got only two values ie api_key and service_id, template_id is undefined why? -当我控制台时,我只有两个值,即 api_key 和 service_id,template_id 未定义,为什么?

You could need to install dotenv您可能需要安装dotenv

And require it on the top of your application并在您的应用程序顶部要求它

require('dotenv').config()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM