如何将Vue开发环境中的端口号修改为长尾词?
- 内容介绍
- 文章标签
- 相关推荐
本文共计523个文字,预计阅读时间需要3分钟。
在Vue开发环境中,修改端口号的步骤如下:
1. 在Vue项目的根目录下,找到名为`config`的文件夹。
2.在`config`文件夹中,打开`index.js`文件。
3.在文件中,找到`devServer`配置项,通常如下所示:
javascript
module.exports={ devServer: { port: 8080 // 默认端口号 } };4. 将端口号`8080`修改为你想要的端口号,例如`3000`。
修改完成后,保存`index.js`文件,然后重启Vue项目即可使用新的端口号。
Vue开发环境中修改端口号
如上图所示,在开发环境中,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 // (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, // 端口号 } };
3.起因
Access to XMLHttpRequest at 'localhost:8080/sockjs-node/info?t=1565711501046' from origin '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,冲突了。至于为什么同一个端口号能运行两个项目,是因为Vue3.0运行时会产生两个项目地址(如下图),我点了后一个......
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持易盾网络。
本文共计523个文字,预计阅读时间需要3分钟。
在Vue开发环境中,修改端口号的步骤如下:
1. 在Vue项目的根目录下,找到名为`config`的文件夹。
2.在`config`文件夹中,打开`index.js`文件。
3.在文件中,找到`devServer`配置项,通常如下所示:
javascript
module.exports={ devServer: { port: 8080 // 默认端口号 } };4. 将端口号`8080`修改为你想要的端口号,例如`3000`。
修改完成后,保存`index.js`文件,然后重启Vue项目即可使用新的端口号。
Vue开发环境中修改端口号
如上图所示,在开发环境中,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 // (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, // 端口号 } };
3.起因
Access to XMLHttpRequest at 'localhost:8080/sockjs-node/info?t=1565711501046' from origin '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,冲突了。至于为什么同一个端口号能运行两个项目,是因为Vue3.0运行时会产生两个项目地址(如下图),我点了后一个......
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持易盾网络。

