学习vue——vue2、vue3与Django路由打通配置

一、vue2与Django路由打通配置

main.js 文件

 1 const { defineConfig } = require('@vue/cli-service')
 2 module.exports = defineConfig({
 3   transpileDependencies: true,
 4   publicPath:'/',
 5   devServer: {
 6     proxy: {
 7         '/api': {
 8             target: 'http://127.0.0.1:8000',// django 后端地址
 9             changeOrigin: true,
10             
11         }
12     },
13     client: {
14         overlay: false
15       }
16 },
17 
18 })

 

二、vue3与Django路由打通配置

vit.config.js

 1 import { defineConfig } from 'vite'
 2 import vue from '@vitejs/plugin-vue'
 3 import WindiCSS from 'vite-plugin-windicss'
 4 import path from 'path'
 5 // https://vitejs.dev/config/
 6 function resolve(dir) {
 7   return path.join(__dirname, dir)
 8 }
 9 export default defineConfig({
10   resolve:{
11     alias:{
12       // "~":path.resolve(__dirname, 'src')
13       '@': resolve('src')
14     }
15   },
16   server:{
17     proxy:{
18       '/api': {
19         target: 'http://127.0.0.1:8000/',
20         changeOrigin: true,
21         rewrite: (path) => path.replace(/^\/api/, '')
22       },
23     }
24   },
25   plugins: [vue(), WindiCSS(),],
26 })

 

posted @ 2024-10-16 14:45  东方不败--Never  阅读(12)  评论(0编辑  收藏  举报