通过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
}
})
0 个回复