简体   繁体   English

Next Js v10 渲染图

[英]Next Js v10 rendering Image

Recently, Next.js version 10 is released with the newest Image element, which is super helpful for a website with a lot of images!最近,Next.js 10 版本发布了最新的Image元素,这对于图片多的网站来说是超级有帮助的!

I get an HTML response from the server something like:我从服务器得到一个 HTML 响应,例如:

HTML =
"<div>
<p> Some Random text</p>
<img src="something" />
<img src="something" />
<img src="something" />
<img src="something" />
 <div>"

All I want to do is render the HTML into plain text and convert all the img tags to Image during rendering on the page.我想要做的就是将 HTML 呈现为纯文本,并在页面呈现期间将所有img标签转换为Image How can I do this to replace all img to Image ?我如何才能将所有img替换为Image

In your React (JSX/TSX) code change all <img> tags to <Image> tags.在您的 React (JSX/TSX) 代码中,将所有<img>标签更改为<Image>标签。

And import it with并导入它

`import Image from 'next/image' `从'下一个/图像'导入图像

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM