网上的资料大多数都是说新建一个vue.config.js
module.exports = {
devServer: {
disableHostCheck: true,
proxy: {
'/api': {
target: 'http://localhost:10010',
changeOrigin: true,
pathRewrite: {
'^/api': ''
}
}
}
}
}
但是这个方法在我这里不奏效,配置在manifest.json的h5中也没有作用。
我的解决方法是在App.vue的同级新建一个vite.config.js文件,这样就解决了。
import {
defineConfig
} from 'vite'
import uni from '@dcloudio/vite-plugin-uni'
export default defineConfig({
plugins: [
uni()
],
server: {
proxy: {
'/api': {
target: 'http://127.0.0.1:10010',// 后端地址
changeOrigin: true,
rewrite: path => path.replace(/^\/api/, ''),
}
}
}
})