问题描述
在vue开发中我们在对脚手架(@vue/cli)进行自定义配置时,在vue.config.js文件里面,会设置以下代码,其中9000是我们自定义的端口号,open则是,启动项目默认开启浏览器的操作;
const { defineConfig } = require('@vue/cli-service')
module.exports = defineConfig({
transpileDependencies: true,
devServer: {
port:9000,
open:true
}
})
如果按照以上代码操作可能会出现报错无法访问此网站如下图
解决方案
以上问题就是配置完了–open,启动项目默认开启浏览器,我们少设置了一个步骤,此时我们需要配置指定的端口号,在vue.config.js文件里面设置host: 'localhost' ,如下代码:
const { defineConfig } = require('@vue/cli-service')
module.exports = defineConfig({
transpileDependencies: true,
devServer: {
host: 'localhost',
port:9000,
open:true
}
})
--❤❤❤❤❤❤-- 温馨提示:最后记得要重启下项目哦!