Day08 React Props-组件属性

component组件之间相互发送数据,传递数据的方式是使用 props。Props代表属性,用於将数据从一个组件传递到另一个组件。
https://ithelp.ithome.com.tw/upload/images/20210923/20139800hcGLYKYZpN.png

今天透过实作,新增一个Card组件,在card组件中先把架构写好

import React from 'react';


const Card = (props) => {
    return (
        <div>
         
          <div className="box">
           <h3>{props.title}</h3>
           <p>{props.of}</p>
           <img
            src={props.imgsrc}  />
           <a href="" class="btn">Buy now</a>
         </div>
            
        </div>
    )
}



export default Card

然後在App.js中汇入,并将app.js中的属性数据传入card.js中,
这样card的内容将由app.js传入的属性数据所决定。

import React from 'react';
import Header1 from "./components/Header1";
import Header2 from "./components/Header2";
import Section1 from "./components/Section1";
import Card from "./components/Card";
import meal from "./assets/images/meal.png"; 
import meal01 from "./assets/images/meal01.png" 


const App = (props) => {
  return (
    <div>
      <Header1 />
      <Header2 />
      <Section1 />
      <Card
             
             title="Steak Meal" 
             of="upto 90% off"
             imgsrc ={meal}             
       />

     <Card             
             title="Hamburger" 
             of="upto 80% off"
             imgsrc ={meal01}             
       />  
       <Card
             
             title=" Pizza" 
             of="upto 70% off"
             imgsrc ={meal}             
       />        
      
    </div>
  )
}

export default App


<<:  Maven + Spring 初探 (一)

>>:  Day-08 你对前端还是後端比较有兴趣?

【Day 6】Replication

决定要拆章节了, 这篇只有 5.1, 5.2 5.3 放明天,因为我好累。 这章会提到 replic...

[Day21]C# 鸡础观念- 物件导向(oop)~类别(class)

万物皆有他的结构, 就如同世界上所有东西皆由元素所组成, 而定义这些结构在C#中称为class, 他...

<Day27> 永丰金iLeader — 查询帐务

● 这章会示范如何透过永丰iLeader查询交易帐务 接续前一章,我们这章来查询股票买卖的交易纪录 ...

Day 28 - 使用各种方式取得资料

这篇会分别使用前面几篇文章介绍的:XHR、Promise、fetch、async、axios 等 5...

@Day27 | C# WixToolset + WPF 帅到不行的安装包 [额外的DLL引用]

套件 在我们写程序时,一定会用很多来支援,让我们更轻松, 尤其是WPF的部分,为了漂亮肯定用了很多套...