vue cli3 环境变量设置

在vue cli 创建的项目里面, 设置环境变量,报错 not defined

问题出现的环境背景及自己尝试过哪些方法

相关代码

// 请把代码文本粘贴到下方(请勿用图片代替代码)\

//.env 文件
VUE_APP_TITLE=测试标题

// public/index.html 

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width,initial-scale=1.0">
    <link rel="icon" href="<%= BASE_URL %>favicon.ico">
    <title><%= VUE_APP_TITLE %></title>
  </head>
  <body>
    <noscript>
      <strong>We're sorry but vue-test-3 doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
    </noscript>
    <div id="app"></div>
    <!-- built files will be auto injected -->
  </body>
</html>

期望页面title显示"测试标题",但是有报错"ReferenceError: VUE_APP_TITLE is not defined"

阅读 7k
2 个回答

process.env.VUE_APP_TITLE

宣传栏