1、在vue项目中,输入命令行  npm run serve   浏览器实现自动打开功能,需要添加 在配置文件(package.json)中添加 --open

2、浏览器自动打开后,可能会出现网址0.0.0.0:8080页面错误,见图

 3、解决方法:

原代码:

const { defineConfig } = require('@vue/cli-service')
module.exports = defineConfig({
  transpileDependencies: true
})

在 vue.config.js 配置文件中添加以下代码:

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

4、命令行 重新输入 npm run serve   浏览器就可以正常自动打开

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐