vue.js 开发环境中怎么改端口号? 下面本篇文章给大家介绍一下 vue 开发环境中修改端口号的实现方法. 有一定的参考价值, 有需要的朋友可以参考一下, 希望对大家有所帮助.
在 vue.JS 开发环境中, 8080 便是端口号, 这也是使用 Vue 脚手架创建的项目运行时的默认的端口. 那么怎么修改默认端口?
1,Vue 2.x
config 文件夹中有一个 index.JS 其中部分内容如下, port 即为端口号, 在这里更改即可.
- module.exports = {
- dev: {
- env: require('./dev.env'),
- port: 8080, // 端口号
- assetsSubDirectory: 'static',
- assetsPublicPath: '/',
- proxyTable: {},
- // CSS Sourcemaps off by default because relative paths are "buggy"
- // with this option, according to the CSS-Loader README
- // (https://github.com/webpack/css-loader#sourcemaps)
- // In our experience, they generally work as expected,
- // just be aware of this issue when enabling this option.
- cssSourceMap: false,
- }
- };
- 2,Vue 3.x
Vue 3.x 中修改端口号则需要在项目根目录下创建一个 vue.config.JS, 内容如下.
module.exports = { devServer: { port: 8080, // 端口号 } };
起因
Access to XMLHttpRequest at 'http://localhost:8080/sockjs-node/info?t=1565711501046' from origin 'http://192.168.0.104:8080' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. localhost:8080/sockjs-node/info?t=1565711501046:1 Failed to load resource: net::ERR_FAILED
开了两个项目, 一个是 Vue2.x, 另一个是 Vue3.x, 看来一下两个的端口号都是 8080, 冲突了.
更多 Web 前端开发 https://www.html.cn/ 知识, 请查阅 HTML 中文网 !!
来源: http://www.css88.com/qa/vue-js/17321.html