Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.8k views
in Technique[技术] by (71.8m points)

vue中我定义的环境变量打包后为什么获取不到了

![](https://img-ask.csdnimg.cn/upload/1606285378279.png?x-oss-process=image/resize,m\_lfit,w\_300/format,png)这是我定义的四个环境文件,

在每个文件里定义了一个新的环境变量VUE\_APP\_COSTURL,

为什么我代码在dev环境打包后,获取不到VUE\_APP\_COSTURL呢

我本地运行 npm run dev-serve都可以获取到VUE\_APP\_COSTURL

....

发现我自己写的VUE\_APP\_COSTURL没用后,我又自己写了一个方法通过自带的NODE\_ENV去判断,发现我把代码传到dev环境打包后,获取的是我对应生产环境prod的url..

有没有大佬解答下我的疑惑啊?我搞了一下午了T-T


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

.env文件vue命名格式

VUE_APP_BASE_API='xxx'

详情见mode-and-env


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...