【发布时间】:2019-06-28 05:10:14
【问题描述】:
如何为开发和生产添加不同的 baseURL?
这是目前我的 nuxt.config.js
module.exports = {
mode: 'universal',
...
axios: {
// See https://github.com/nuxt-community/axios-module#options
baseURL: 'http://10.8.0.1:8000',
credentials: false
},
...
}
对于 npm run dev 和 npm run generate 我想要不同的 baseURL。
我该怎么做?
编辑
// nuxt.config.js
export default {
env: {
baseUrl: process.env.BASE_URL || 'http://localhost:3000'
}
}
console.log(process.env.BASE_URL) // <-- The output is correct (I get the BASE_URL from my env variables
module.exports = {
...
axios: {
baseURL: process.env.baseUrl // <-- This is not working, why?
},
...
}
【问题讨论】:
-
你可以使用环境变量
-
你有一个有效的例子吗?我不懂文档:nuxtjs.org/api/configuration-env
-
你解决过这个问题吗?