// vue.config.ts
export default defineConfig({
plugins: [
vue(),
vueJsx(),
],
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url))
}
},
server: {
proxy: {
'/api': {
target: 'http://127.0.0.1',
changeOrigin: true,
rewrite: path => path.replace(/^\/api/, 'api')
}
},
}
})
// 其他view文件中请求url这样写
function getData() {
axios.get('/api/user/getAllUsers') // 或者 http://localhost:5173/api/user/getAllUsers 而不是 http://localhost:80/api/user/getAllUsers 想代理成的网址
.then(res => {
console.log(res)
})
}
网友评论