请求接口会产生跨域问题,需要做个代理服务器配置
在vite.config.ts中进行配置:
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: {
proxy: {
// 选项写法
'/ConfigProperties': {
target: 'http://localhost:5000',
changeOrigin: true,
//rewrite: (path) => path.replace(/^\/api/, '')
}
}
}
})
这样就解决了跨域问题
具体参考vite官网 开发服务器选项 | Vite 官方中文文档