We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
在nuxt中使用axios插件 在plugins插件中加入axios.js
... var baseURL =context.baseUrl|| env.baseUrl console.log('baseURL=', baseURL) if(process.server){ $axios.setBaseURL(baseURL) }else{ $axios.setBaseURL(window.location.origin) } ...
这里会对不同环境做判断
起因:asyncData 中使用axios 默认使用是本地的80端口,(这货估计压根没想到使用端口访问的问题,以为大家都是Nginx 做反向代理)死活调不通API , 正式环境的请求中出现 http://localhost:3000 这种请求
肯定不能在代码中写死线上地址的API ,于是换到在packa.json 中使用 环境变量的方式,改为如下
... "scripts": { "dev": "cross-env NODE_ENV=development REMOTE_URL=http://线上IP:5000 BASE_URL=http://localhost:3000 nodemon server/index.js --watch server", "build": "cross-env NODE_ENV=production REMOTE_URL=http://127.0.0.1:5000 BASE_URL=http://127.0.0.1:3000 nuxt build", "start": "cross-env NODE_ENV=production REMOTE_URL=http://127.0.0.1:5000 BASE_URL=http://127.0.0.1:3000 node server/index.js", "generate": "nuxt generate" }, ...
使用 yarn build后一切恢复正常
yarn build
The text was updated successfully, but these errors were encountered:
No branches or pull requests
在nuxt中使用axios插件
在plugins插件中加入axios.js
这里会对不同环境做判断
起因:asyncData 中使用axios 默认使用是本地的80端口,(这货估计压根没想到使用端口访问的问题,以为大家都是Nginx 做反向代理)死活调不通API , 正式环境的请求中出现 http://localhost:3000 这种请求
肯定不能在代码中写死线上地址的API ,于是换到在packa.json 中使用 环境变量的方式,改为如下
使用
yarn build
后一切恢复正常The text was updated successfully, but these errors were encountered: