解决uni-app中的本地跨域

关于在HbuilderX中的uni-app的本地跨域的代理解决方式:

此方式是在vue3中语法生效,如下:

创建vite.config.js,并在js中输入一下内容:

import { defineConfig } from 'vite';
import uni from '@dcloudio/vite-plugin-uni';

export default defineConfig({
  plugins:[uni()],
  server:{
    hmr:true,
    proxy:{
      '/api':{
        target:'https://60.214.234.34:8006/sdt/',
        changeOrigin:true,
        rewrite:path=>path.replace(/^\/api/,''),
        secure:false
      }
    }
  }
})

然后再baseUrl.js中的请求地址改成/api即可。

posted @ 2024-12-27 09:35  星宝攸宁  阅读(551)  评论(0)    收藏  举报