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

輸出量

React JS | Adding Images in React JS Application

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 添加樣式

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/379179.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/379179.shtml
英文地址,請注明出處:http://en.pswp.cn/news/379179.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

二叉樹(多路平衡搜索樹)-(代碼、分析、匯編)

目錄&#xff1a;代碼&#xff1a;分析&#xff1a;匯編&#xff1a;代碼&#xff1a; BTree.h #ifndef _BTREE_H_ #define _BTREE_H_#define BT_LEFT 0 //定義左子節點標識 #define BT_RIGHT 1 //定義右子節點標識typedef void BTree;//定義樹類型 typedef unsigned long lo…

window service服務安裝錯誤

今天按照園子里面的文章&#xff0c;弄了一個系統服務&#xff0c;可是一直裝不上去&#xff0c; 正在運行事務處理安裝。 正在開始安裝的“安裝”階段。查看日志文件的內容以獲得 D:\TecCreateSvc\TecJsCreateService.exe 程序集的進度。該文件位于 D:\TecCreateSvc\TecJsCre…

DM9000調試記錄

最近在調試DM9000&#xff0c;遇到了很多問題&#xff0c;在網上幾乎也能找到同樣的問題&#xff0c;但是答案千變萬化&#xff0c;弄的我這樣不行&#xff0c;那樣也不行。 1、遇到的第一個問題&#xff0c;網卡不識別&#xff0c;出現的調試信息就是&#xff1a; dm9000 dm90…

Python---二分法查找

輸入n個數&#xff0c;通過二分法查找該數的下標 def binarySearch(arr,value):m 0#開始n len(arr#最后)while m<n:mid(mn)//2#計算中間位置if valuearr[mid]:#查找成功&#xff0c;返回元素對應的位置return midelif value>arr[mid]:#在后面一半元素中繼續查找mmid1e…

Python datetime isocalendar()方法與示例

Python datetime.isocalendar()方法 (Python datetime.isocalendar() Method) datetime.isocalendar() method is used to manipulate objects of datetime class of module datetime. datetime.isocalendar()方法用于操作模塊datetime的datetime類的對象。 It uses a dateti…

ASP.NET 技術(附翻譯)

1.構建 ASP.NET 頁面ASP.NET 和ASP.NET結構ASP.NET 是微軟.NET framework整體的一部分, 它包含一組大量的編程用的類&#xff0c;滿足各種編程需要。 在下列的二個部分中, 你如何學會 ASP.NET 很適合的放在.NET framework, 和學會能在你的 ASP.NET 頁面中使用語言。.NET類庫假想…

SQL捕獲異常

原文地址 http://technet.microsoft.com/zh-cn/office/ms179296%28vsql.100%29在 Transact-SQL 中使用 TRY...CATCHTransact-SQL 代碼中的錯誤可使用 TRY…CATCH 構造處理&#xff0c;此功能類似于 Microsoft Visual C 和 Microsoft Visual C# 語言的異常處理功能。TRY…CATCH …

二叉樹遍歷(代碼,分析,匯編)

目錄&#xff1a;代碼&#xff1a;分析&#xff1a;匯編&#xff1a;代碼&#xff1a; BTree.h BTree.c 二叉樹&#xff08;多路平衡搜索樹&#xff09; LinkQueue.h #ifndef _LINKQUEUE_H_ #define _LINKQUEUE_H_typedef void LinkQueue;//定義隊列類型LinkQueue* LinkQueu…

Java Vector insertElementAt()方法與示例

矢量類insertElementAt()方法 (Vector Class insertElementAt() method) insertElementAt() method is available in java.util package. insertElementAt()方法在java.util包中可用。 insertElementAt() method is used to set the given element (ele) at the given (indices…

Python---查找序列的最長遞增子序列

查找序列的最長遞增子序列 什么是序列的最長遞增子序列&#xff1f; 答&#xff1a;在一個數值序列中&#xff0c;找到一個子序列&#xff0c;使得這個子序列元素的數值依次遞增&#xff0c;并且這個子序列的長度盡可能地大。這就是所謂的最長遞增子序列 from itertools impo…

SendMessage和PostMessage

SendMessage 和 PostMessage 的區別 &#xff11;、首先是返回值意義的區別&#xff0c;我們先看一下 MSDN 里的聲明&#xff1a; LRESULT SendMessage( HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);BOOL PostMessage( HWND hWnd…

ffmpeg-從mp4、flv、ts文件中提取264視頻流數據

ffmpeg-從mp4、flv、ts文件中提取264視頻流數據 main.c #include <stdio.h> #include <libavutil/log.h> #include <libavformat/avio.h> #include <libavformat/avformat.h>void proc(int need_to_annexb, char* in_file, char* out_file) {AVForma…

java timezone_Java TimeZone getDSTSavings()方法與示例

java timezoneTimeZone類的getDSTSavings()方法 (TimeZone Class getDSTSavings() method) getDSTSavings() method is available in java.util package. getDSTSavings()方法在java.util包中可用。 getDSTSavings() method is used to get the number of time differences in …

Photoshop 保存PNG格式交錯和不交錯有差別

1.PNG格式是由Netscape公司開發出來的格式&#xff0c;可以用于網絡圖像&#xff0c;但它不同于GIF格式圖像只能保存256色&#xff0c;PNG格式可以保存24位的真彩色圖像&#xff0c;并且支持透明背景和消除鋸齒邊緣的功能&#xff0c;可以在不失真的情況下壓縮保存圖像。但由于…

線索化二叉樹(代碼 、分析 、匯編)

目錄&#xff1a;代碼&#xff1a;分析&#xff1a;匯編&#xff1a;代碼&#xff1a; BTree.h BTree.c 二叉樹&#xff08;多路平衡搜索樹&#xff09; SeqList.h SeqList.c 順序表 main.c #include <stdio.h> #include <stdlib.h> #include "BTree.h&qu…

Python---尋找給定序列中相差最小的兩個數字

編寫函數&#xff0c;尋找給定序列中相差最小的兩個數字 def getTwoClosestElements(arr):#先進行排序&#xff0c;使得相鄰元素最接近#相差最小的元素必然相鄰seq sorted(arr)#先進行排序dif float(inf)#無窮大#遍歷所有元素&#xff0c;兩兩比較&#xff0c;比較相鄰元素的…

ubuntu 無線 共享 上網

配置DHCP服務器 使連接到此AP的電腦 自動獲取IP 1. 安裝軟件包&#xff1a;sudo apt-get install dhcp3-server2. 修改/etc/default/dhcp3-server配置文件INTERFACES"eth1" //eth1為無線網卡的名字3. 修改/etc/dhcp3/dhcpd.conf配置文件option domain-name-servers …

Java StringBuilder getChars()方法與示例

StringBuilder類的getChars()方法 (StringBuilder Class getChars() method) getChars() method is available in java.lang package. getChars()方法在java.lang包中可用。 getChars() method is used to copy all the characters from the given arguments (int src_st, int …

Python---利用蒙特.卡羅方法計算圓周率近似值

利用蒙特.卡羅方法計算圓周率近似值 什么是蒙特.卡羅方法&#xff1f; 答&#xff1a;蒙特卡羅方法是一種計算方法。原理是通過大量隨機樣本&#xff0c;去了解一個系統&#xff0c;進而得到所要計算的值。 正方形內部有一個相切的圓&#xff0c;它們的面積之比是π/4。 這里假…

不具有繼承關系的Delegate如何進行類型轉換?

- 引自:Artech 我們知道對于兩個不具有繼承關系的兩個類型&#xff0c;如果沒有為它們定義轉換器&#xff0c;兩這之間的類型轉換是不允許的&#xff0c;Delegate也是如此。但是有時候我們卻希望“兼容”的兩種Delegate類型能夠進行轉換&#xff0c;比較典型的就是表示事件的De…