thinkphp6 中间件的使用 解决跨域问题
2022-11-24 11:10:29
160
{{single.collect_count}}

当前后端分离,跨域时需要使用到中间件

在文件middleware.php 文件中需要创建 代码

<?php// 全局中间件定义文件return [// 全局请求缓存// \think\middleware\CheckRequestCache::class,// 多语言加载// \think\middleware\LoadLangPack::class,// Session初始化// \think\middleware\SessionInit::class\app\middleware\CrossDomain::class];

 在文件夹下面创建CrossDomain.php 文件,代码为

<?php/** * Created by phpstorm * User: loveAKY * Date: 2021/1/18 * Time: 17:06 */namespace app\middleware;use think\Response;/** * 跨域设置 */class CrossDomain{/** * [handle 设置跨域] * @Author 1076986776@qq.com * @DateTime 2022-02-03 * @version[version] * @param[ty
回帖
全部回帖({{commentCount}})
{{item.user.nickname}} {{item.user.group_title}} {{item.friend_time}}
{{item.content}}
{{item.comment_content_show ? '取消' : '回复'}} 删除
回帖
{{reply.user.nickname}} {{reply.user.group_title}} {{reply.friend_time}}
{{reply.content}}
{{reply.comment_content_show ? '取消' : '回复'}} 删除
回帖
收起
没有更多啦~
{{commentLoading ? '加载中...' : '查看更多评论'}}