“我调用了一个以xml svg格式返回qrcode api。我想在刀片视图中显示该qrcode。我要在刀片视图中显示xml svg响应。”
我从调用的API中获取控制器中的xml svg qrcode,我希望在刀片中显示它
在控制器中,这就是我将数据呈现到刀片中方式
return response()
->view(
'qrcode',
[
'output' => $output
],
200
)
->header('Content-Type', 'image/svg+xml');这是我的刀片的样子:
<svg {{$output}}></svg>我希望在刀片视图上看到svg xml qrcode ($output变量包含它)变量
发布于 2019-08-07 20:29:06
将输出放在svg标记之间
<svg>{{ $output }}</svg>发布于 2019-08-07 20:33:20
您需要创建一个Response并将标头附加到它,而不是视图。
$response = Response::make(View::make('qrcode', ['output' => $output]), 200);
$response->header('Content-Type', 'image/svg+xml');
return $response;我还建议只在视图中添加标题:
<?php header('Content-Type: image/svg+xml'); ?>
{{ $output }} <!-- Try without SVG tags seems as you have XML tags in your $output anyway -->有关更多信息,请参阅Laravel Docs
发布于 2021-08-12 05:47:53
试试这个,它对我很有效:
<?php
$file_path = file_get_contents(public_path('client/assets/images') .'/'. $filename);
return response($file_path)->header('Content-Type', 'image/svg+xml');
/*The public path above is path to *.svg file*/
?>此外,我们还可以在图像标记上使用它,如下所示:
<img src="/assets/images/logo.svg" />https://stackoverflow.com/questions/57394483
复制相似问题