当前位置: 移动技术网 > IT编程>脚本编程>vue.js > Vue开发环境中修改端口号的实现方法

Vue开发环境中修改端口号的实现方法

2019年09月06日  | 移动技术网IT编程  | 我要评论

秦宜智的父亲,s2m-006,想瞬谱

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
    // (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,   // 端口号
  }
};

3.起因

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,冲突了。至于为什么同一个端口号能运行两个项目,是因为vue3.0运行时会产生两个项目地址(如下图),我点了后一个......

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持移动技术网。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网