0
点赞
收藏
分享

微信扫一扫

vue项目运行后自动打开浏览器

黎轩的闲暇时光 2022-03-12 阅读 63
  1. 在根目录下 config/index.js 文件内增加 autoOpenBrowser : true
module.exports = {
  dev: {
     assetsSubDirectory: 'static',
     assetsPublicPath: '/',
     proxyTable: {
        //代理
        // "/api": {
        //   target: "http://localhost:3000",//接口的域名
        //   pathRewrite: {
        //     "^/api": "http://localhost:3000"     //需要将/api重写为''
        //   },
        //   secure: false,    // 如果是https接口,需要配置这个参数
        //   changeOrigin: true// 如果接口跨域,需要进行这个参数配置
        // }
     },
     autoOpenBrowser: true,
  }
}
  1. 在根目录下 vue.config.js 文件内增加 open : true
module.exports = {
    publicPath: '/',
    outputDir: 'dist',
    assetsDir: 'static',
    lintOnSave: process.env.NODE_ENV === 'production',
    productionSourceMap: false,
    runtimeCompiler: true,
    devServer: {
        port: port,
        open: true,
        overlay: {
            warnings: false,
            errors: true
        },
        // before: require('./mock/mock-server.js')
    },
}
  1. 在 package.json文件内,scripts运行的脚本后增加 --open
{
  "name": "vue-element-admin",
  "version": "3.8.0",
  "description": "A magical vue admin. An out-of-box UI solution for enterprise applications. Newest development stack of vue. Lots of awesome features",
  "author": "GavinL <852213985@qq.com>",
  "scripts": {
    "dev": "vue-cli-service serve --open",
    "lint": "eslint --ext .js,.vue src",
    "build:prod": "vue-cli-service build",
    "build:stage": "vue-cli-service build --mode staging",
  }
}
举报

相关推荐

0 条评论