创建的是vue3的项目,开始配置跨域我还以为在vue.config.js里面配置,结果配置了半天发现根本没有效果,下载了vue cli也不行,在各路大佬的带领下终于发要看package.json包,
"scripts": {
"dev": "vite",
"build": "vite build",
"preview": "vite preview --port 8085"
},
包里面启动是用的vite,那么配置就要配置在vite.config.js里面。
下面就是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:{
proxy: {
"/api": {
target: "http://localhost:7001",
changeOrigin: true,
rewrite: (path) => path.replace(/^\/api/, ""),
},
},
}
})