THINKPHP6跨域问题
thinkphp有内置的跨域中间件只需要开启就可以了
在app/middleware.php中开启一下
//允许跨域
think\middleware\AllowCrossDomain::class
www WEB部署目录(或者子目录)
├─app 应用目录
│ ├─controller 控制器目录
│ ├─model 模型目录
│ ├─middleware.php 中间件
│ │
│ ├─common.php 公共函数文件
│ └─event.php 事件定义文件
<?php
// 全局中间件定义文件
return [
//允许跨域
\think\middleware\AllowCrossDomain::class
//更多...
];
vite.config.ts中
export default defineConfig({
server:{
proxy:{
'/api':{
target:"http://127.0.0.1:8000",
changeOrigin: true,
rewrite: path => path.replace(/^\/api/, '')
}
}
}
})