【报错系列】vue设置项目运行起来的时候,让浏览器自动打开,报错信息为:网址为 http://0.0.0.0:8080/ 的网页可能暂时无法连接,或者它已永久性地移动到了新网址

1- 报错问题


用脚手架创建Vue2项目,设置项目运行起来的时候,让浏览器自动打开;

// 在package.json  文件夹

"scripts":{
    
    
	"serve":"vue-cli-service serve --open",
	"build""vue-cli-service build",
     "lint": "vue-cli-service lint"
}

当执行npm run serve后,浏览器自动打开后报错了,显示:
网址为 http://0.0.0.0:8080/ 的网页可能暂时无法连接,或者它已永久性地移动到了新网址。

在这里插入图片描述

2- 解决方案


vue.config.js中添加代码

devServer: {
    
    host: ‘localhost’,port: 8080 }

如果没有vue.config.js文件的,在根目录下创建一个,把下面代码复制进去即可

const {
    
     defineConfig } = require('@vue/cli-service')
module.exports = defineConfig({
    
    
  transpileDependencies: true,
  devServer:{
    
    
    host:'localhost',
    port:8080
  }
})

在这里插入图片描述

添加完之后,就可以运行 npm run serve ,就可以自动打开浏览器运行了

猜你喜欢

转载自blog.csdn.net/qq_59012240/article/details/129026353
今日推荐