【问题标题】:Change client side configuration after nuxt buildnuxt 构建后更改客户端配置
【发布时间】:2019-02-04 13:10:49
【问题描述】:

我想知道是否可以在 nuxt 构建发生后更改客户端配置。 场景是:构建一次,部署在具有一些配置变化的多个环境上。

我很清楚,您可以使用环境变量(如 API_URL)影响某些参数,但它似乎不会影响客户端执行。

例子:

  • 在 nuxt.config.js 中有 axios.baseURL = api/v1
  • nuxt 构建
  • nuxt 开始
  • 服务器和客户端请求转到 api/v1
  • 设置环境变量 API_URL= api/v2
  • nuxt 启动(不重新构建)
  • 服务器端请求转到 api/v2,客户端请求转到 api/V1。预期行为:服务器和客户端请求转到 api/v2 我错过了什么?

感谢您的帮助! 塞德里克

【问题讨论】:

    标签: nuxt.js


    【解决方案1】:

    你可以使用 nuxt-env 模块 https://github.com/samtgarson/nuxt-env

    export default {
      computed: {
        testValue () { return this.$env.TEST_VALUE }
      }
    }
    

    【讨论】:

      猜你喜欢
      • 2023-03-29
      • 2019-12-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多