修改 vite.config.js 配置文件
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
const { resolve } = require('path')
export default defineConfig({
// 起个别名,在引用资源时,可以用‘@/资源路径’直接访问
resolve: {
alias: {
"@": resolve(__dirname, "src"),
},
},
plugins: [vue()],
// 配置前端服务地址和端口
server: {
host: '0.0.0.0',
port: 8991,
// 是否开启 https
https: false,
},
// 设置反向代理,跨域
proxy: {
'/api1': {
// 后台地址
target: 'http://127.0.0.1:8990/',
changeOrigin: true,
rewrite: path => path.replace(/^\/api1/, '')
},
'/api2': {
// 后台地址
target: 'http://127.0.0.1:8956/',
changeOrigin: true,
rewrite: path => path.replace(/^\/api2/, '')
}
}
})
标签:vue,api1,api2,访问,resolve,vite,path,调试
From: https://www.cnblogs.com/rise0111/p/17425830.html