
如上图所示,在开发环境中,
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运行时会产生两个项目地址(以下图),我点了后一个......
