首页
关于
Search
1
webman跨域问题
4 阅读
2
flutter 中web应用,在微信开发工具打开链接,报错imageCodecException
3 阅读
默认分类
登录
Search
Typecho
累计撰写
2
篇文章
累计收到
0
条评论
首页
栏目
默认分类
页面
关于
搜索到
2
篇与
的结果
2025-10-28
webman跨域问题
接口等跨域访问增加中间件如下:use Webman\Http\Response; use Webman\Http\Request; use Webman\MiddlewareInterface; class CrossDomain implements MiddlewareInterface { public function process(Request $request, callable $handler): Response { $response = $request->method() == 'OPTIONS' ? response('') : $handler($request); // 给响应添加跨域相关的http头 $response->withHeaders([ 'Access-Control-Allow-Credentials' => 'true', 'Access-Control-Allow-Origin' => $request->header('origin', '*'), 'Access-Control-Allow-Methods' => $request->header('access-control-request-method', '*'), 'Access-Control-Allow-Headers' => $request->header('access-control-request-headers', '*'), ]); return $response; } }并在config/middleware.php中修改:return [ '' => [ CrossDomain::class ], ];如果是资源类跨域问题,需要注意就是,官方的后台管理插件和webman需要分别设置跨域中间件:class StaticFile implements MiddlewareInterface { public function process(Request $request, callable $handler): Response { // Access to files beginning with. Is prohibited if (strpos($request->path(), '/.') !== false) { return response('<h1>403 forbidden</h1>', 403); } /** @var Response $response */ $response = $handler($request); // Add cross domain HTTP header $response->withHeaders([ 'Access-Control-Allow-Origin' => '*', 'Access-Control-Allow-Credentials' => 'true', ]); return $response; } }webman在static.php中设置,webman的管理后台插件,需要在插件中的static.php设置,设置如下:return [ 'enable' => true, 'middleware' => [ // Static file Middleware StaticFile::class, ], ];
2025年10月28日
4 阅读
0 评论
0 点赞
2025-10-28
flutter 中web应用,在微信开发工具打开链接,报错imageCodecException
报错如下:imageCodecException: Failed to decode image using the browser's ImageDecoder API.Image source: encoded image bytesOriginal browser eror: Expected a value of type'JSObject,but gotene of type'Null'原因分析:这个错误是 Flutter Web 在微信开发者工具中遇到的图像解码问题解决方法:修改 Flutter Web 渲染设置在 web/index.html 中添加以下配置:<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>My Flutter App</title> <!-- 添加以下 meta 标签 --> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="IE=Edge"> <!-- 禁用某些浏览器特性 --> <script> window.flutterWebRenderer = "html"; // 强制使用 HTML 渲染器 </script> <script src="main.dart.js" type="application/javascript"></script> </head> <body> <script> // 图像加载错误处理 window.addEventListener('error', function(e) { if (e.target && (e.target.tagName === 'IMG' || e.target.tagName === 'IMAGE')) { console.log('Image load error:', e.target.src); e.preventDefault(); } }, true); </script> </body> </html>
2025年10月28日
3 阅读
0 评论
1 点赞