我有一个像这样的脚本:
const item = [
companyid : 23,
summaryid : 2
];
const url = process.env.urlLink;
我想像这样在url
中设置.env
:
urlLink = "https://example.com/print/index/companyid=" + item.companyid + "&summaryid=" + item.summaryid
当我console.log(url)
时,我想获得以下值:
https://example.com/print/index/companyid=23&summaryid=2
但是我总是得到这个值:
https://example.com/print/index/companyid=" + item.companyid + "&summaryid=" + item.summaryid
如何获取变量item.companyid
和item.summaryid
?
答案 0 :(得分:1)
尝试一下:
在.env文件中:
companyid = 23
summaryid = 2
LINK = "https://example.com/print/index/companyid="
在js文件中:
console.log(process.env.LINK + process.env.companyid + "&summaryid=" + process.env.summaryid)
输出:
https://example.com/print/index/companyid=23&summaryid=2
答案 1 :(得分:0)
这不是一个非常优雅的解决方案,但是它可以工作
放在.env上
companyid : 23
summaryid : 2
LINK = "https://example.com/print/index/companyid="
放在日志上
console.log(process.env.LINK + process.env.companyid + "&summaryid=" + process.env.summaryid)
答案 2 :(得分:0)
只需保留脚本中的数组,您的.env文件应如下所示:
urlLink = "https://example.com/print/index/companyid="
PARAM = "&summaryid="
然后是您的脚本
console.log(process.env.urlLink + item.companyid + process.env.PARAM + item.summaryid)