日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > javascript >内容正文

javascript

react js 添加样式_如何在React JS Application中添加图像?

發布時間:2023/12/1 javascript 42 豆豆
生活随笔 收集整理的這篇文章主要介紹了 react js 添加样式_如何在React JS Application中添加图像? 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

react js 添加樣式

Hello! In this article, we will learn how to add images in React JS? I remember when I just started coding in React JS, I thought adding images would be done exactly as it is in HTML. I later realized that it was different.

你好! 在本文中,我們將學習如何在React JS中添加圖像? 我記得當我剛開始在React JS中編碼時,我以為添加圖像將完全像在HTML中那樣進行。 后來我意識到這是不同的。

Let's quickly look at its syntax or how it is done?

讓我們快速看一下它的語法或如何完成的?

Just like in HTML, having the image in the same folder with the image makes it easy getting the file location URL.

就像在HTML中一樣,將圖像與圖像放在同一文件夾中可輕松獲取文件位置URL。

We equally ought to know the extension with our image.

我們同樣應該知道我們形象的延伸。

Open your index.js file and type the following as usual,

打開index.js文件,然后像往常一樣鍵入以下內容,

import React from 'react' import ReactDOM from 'react-dom' import App from './App'ReactDOM.render(<App />, document.getElementById('root'))

From React JS basics, the code above simply imports the required dependencies, components and renders everything to the root node.

從React JS基礎開始,以上代碼僅導入所需的依賴項,組件并將所有內容呈現到根節點。

import React from "react" import Img from './congrats.png'class App extends React.Component {render() {return (<div> <center><img src= {Img} alt="pic" /><br/> <b> CONGRATS </b></center></div>)} } export default App

From the code above, we added the image congrats.png using the syntax <img src = {Img} alt="pic" />.

從上面的代碼中,我們使用語法<img src = {Img} alt =“ pic” />添加了圖像congrats.png 。

We first of all import the image as seen in the second line above.

首先,如上第二行所示,導入圖像。

The term Img is not conventional and any name can be used, provided it is equally used the same when writing the image tag.

術語Img不是常規名稱,可以使用任何名稱,只要在寫入圖像標簽時使用相同的名稱即可。

Congrats.png is the name of my image and its an extension is PNG.

Congrats.png是我的圖像的名稱,其擴展名為PNG。

When writing the tag, we enclose {Img} in curly braces and the tag ends with / > which is a convention in JSX.

編寫標記時,我們將{Img}括在花括號中,并且標記以/>結尾,這是JSX中的約定。

Also note that, all react JS image tags must have an alternate (alt).

另請注意, 所有react JS圖像標簽都必須具有備用 ( alt )。

Output

輸出量

Thanks for coding with me! See you @ the next article. Feel free to drop a comment or question.

感謝您與我編碼! 下次見。 隨意發表評論或問題。

翻譯自: https://www.includehelp.com/react-js/how-to-add-an-image-in-react-js-application.aspx

react js 添加樣式

總結

以上是生活随笔為你收集整理的react js 添加样式_如何在React JS Application中添加图像?的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。