【问题标题】:asp.net core environment variable not passing to vuejs configasp.net 核心环境变量未传递给 vuejs 配置
【发布时间】:2021-06-14 16:38:57
【问题描述】:

我正在尝试将 asp.net core (kesterl) 中的环境变量设置传递给 vuejs 我的启动设置就像

{
  "iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iisExpress": {
      "applicationUrl": "https://localhost:44323/",
      "sslPort": 44323
    }
  },
  "$schema": "http://json.schemastore.org/launchsettings.json",
  "profiles": {
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development",
        "BEAPI_URL": "http://localhost:4000/api/v1",
        "VUE_BEAPI_URL": "http://localhost:4000/api/v1"
      }
    },    
  }
}

我的 vuejs 配置如下

export default {
    // apiUrl: 'http://localhost:4000/api/v1'    
    apiUrl: process.env.VUE_BEAPI_URL
    
}

任何人都喜欢我的场景 除此之外,我的 vuejs 应用程序在 kesterl 下运行良好

【问题讨论】:

  • 你使用的是什么版本的 vue.js?可能您需要将前缀 VUE_APP_ 添加到 ENV 以使它们在您的 vue.js 应用程序中可用。 stackoverflow.com/q/50828904/83039
  • 我试过加VUE_APP_后缀但是没有效果。 vuejs 版本是 2.6.12

标签: vue.js asp.net-core kestrel-http-server


【解决方案1】:

以下设置有效 kesterl 启动设置(用于环境变量名称参考)

{
  "iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iisExpress": {
      "applicationUrl": "https://localhost:44323/",
      "sslPort": 44323
    }
  },
  "$schema": "http://json.schemastore.org/launchsettings.json",
  "profiles": {
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development",
        "VUE_APP_BEAPI_URL": "http://localhost:4000/api/v1"
      }
    }
  }
}

vuejs 配置

export default {
    // apiUrl: 'http://localhost:4000/api/v1',
    apiUrl: process.env.VUE_APP_BEAPI_URL,
    access_token:''
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-11-08
    • 2020-10-17
    • 1970-01-01
    • 2013-12-29
    • 1970-01-01
    • 2021-09-05
    • 2020-03-27
    • 2017-03-30
    相关资源
    最近更新 更多