Vue default startup project automatically opens the browser, URL http://0.0.0.0:8080

Automatically open browser URL 0.0.0.0:8080 Problem:

In vue.config.js: I initially configured it like this, and the browser opens 0.0.0.0:8080 by default

 devServer: { //代理
    // host: process.env.Host || "localhost",
    host: process.env.Host || "0.0.0.0",
    port: 8080,
    open: true,
    compress:true
  },

In vue.config.js: We only need to change the host to 'localhost' and restart pnpm run serve to solve this problem

 devServer: { //代理
    host: process.env.Host || "localhost",
    port: 8080,
    open: true,
    compress:true
  },

Although the problem of automatic opening is solved, I have found a new problem with this setting. The following status becomes the same. If the host is changed to 0.0. .=

Finally, through verification, it is found that it is related to the version of vue-cli. There is no problem with the configuration of the version below vue-cli5. It is a perfect solution.

 devServer: { //代理
    // host: process.env.Host || "localhost",
    host: process.env.Host || "0.0.0.0",
    port: 8080,
    open: true,
    compress:true
  },

Configuration above vue-cli5

const { defineConfig } = require('@vue/cli-service')
module.exports = defineConfig({
  transpileDependencies: true,
  lintOnSave:false,    //禁用eslint报错   好恶心--
  // 跨域配置  
  devServer:{
    // host:"localhost",
    // port:8080,
    https:false,
    // 跨域配置
    proxy:{
      "/api":{
        target:"http://127.0.0.1:8080",
        changOrigin:true,
        ws:true,
        pathRewrite:{
          "^/api":""
        }
      }
    }
  }
})

Note: The host and prot here are just the default ones. It is normal for us to run without configuration!

You can also set it if you have to! It's just that the status value becomes the same and doesn't affect the project


 

 

Guess you like

Origin blog.csdn.net/qq_44535402/article/details/127075309