5***@qq.com
5***@qq.com
  • 发布:2022-11-07 17:26
  • 更新:2022-11-07 17:26
  • 阅读:214

uniapp 使用vue3打包h5后的跨域问题

分类:HTML5+

通过hbuilderX 发行-》网站 进行项目打包后
直接打开index.html 控制台报错
from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, isolated-app, chrome-extension, chrome, https, chrome-untrusted.

vite.config.js 代码如下
import { defineConfig } from 'vite'
import uni from '@dcloudio/vite-plugin-uni';
// import env from '@/common/env.js';

// https://vitejs.dev/config/
export default defineConfig({
plugins: [
uni()
],
server: {
port:3000,//启动端口
open: true,
proxy: {
'/apiTest': {
// target:'http://192.168.13.169:80/apiTest',
target:'http://127.0.0.1:8080',
// target:'http://172.16.28.84:8080',
changeOrigin: true,
rewrite: (path) => path.replace(/^\/apiTest/, '')
}
},
cors:true
}
})

2022-11-07 17:26 负责人:无 待确认修改 1 分享
已邀请:

要回复问题请先登录注册