修改vite.config.js文件
import { fileURLToPath, URL } from 'node:url'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
vue(),
],
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url))
}
},
server: {
host: '0.0.0.0',//这个地方设置为0.0.0.0,即访问127.0.0.1也行,访问局域网ip也行(例192.168.x.x)
port: 5173, // 监听的端口号
}
})