在ReactJS中显示来自URL的图像 [英] Display an image from url in ReactJS
本文介绍了在ReactJS中显示来自URL的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在React中显示来自URL的图像.例如,我想要这张图片
I want to display an image from a URL in React. For example, I want this image
https://images.pexels.com/photos/20787/pexels-photo.jpg?auto=compress&cs=tinysrgb&h=350
显示在Card主体或reactJS中.是否可以执行此操作,或者必须先将其下载到资产中才能显示?以及如何做到?
to be displayed in a Card body or reactJS. Is it possible to do it or do I have to download it to assets before I can display it? And how to do it?
推荐答案
就像在HTML中一样
import React from "react";
import ReactDOM from "react-dom";
function App() {
return (
<img
src="https://images.pexels.com/photos/20787/pexels-photo.jpg?auto=compress&cs=tinysrgb&h=350"
alt="new"
/>
);
}
const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);
这篇关于在ReactJS中显示来自URL的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文