Vue3 在vite中运行无法使用外部ip访问

使用vite创建的vue项目运行时,只能使用localhost(127.0.0.1)访问,如果使用外部ip,提示使用–host参数,可使用npm run dev --host,不起作用,在host后增加0.0.0.0也不起作用。需要运行npx vite --host 0.0.0.0。还有一个办法,就是在vite.config.js中增加配置server:

export default defineConfig({
    
    
  plugins: [vue()],
  server: {
    
    
    host: "0.0.0.0" 
  },

猜你喜欢

转载自blog.csdn.net/qq_52099965/article/details/128313896