zoukankan      html  css  js  c++  java
  • react组件传值(props[只读属性]) 函数组件

    组件间传值,在React中是通过只读属性 props 来完成数据传递的。

    props:接受任意的入参,并返回用于描述页面展示内容的 React 元素。

    function Cmp1(props) {

        return (

          <div>

            <h3>{ props.name } -- 你好世界</h3>

          </div>

        )

    }

    父组件

      
    // react根组件
    import React, { Component } from 'react'
    
    // 导入
     import Items from './components/Items'
    render() {
        return (
          <div>
            <Items title="我父组件给你的信息" num={100} bool={true} /> 
          </div>
        )
      }

    子组件

    import React from 'react';
    
    // props是一个只读属性,不能进行数据修改const Items = (props) => {
      console.log(props)
      return (
        <div>
          我是一个函数组件
          <hr />
          <h3>{props.title}</h3>
        </div>
      );
    } 
    
    /* const Items = (props) => {
      let {title} = props
      return (
        <div>
          我是一个函数组件
          <hr />
          <h3>{title}</h3>
        </div>
      );
    } */
    export default Items;
     
    右侧打赏一下 代码改变世界一块二块也是爱
  • 相关阅读:
    hdu4059 The Boss on Mars
    cf475D CGCDSSQ
    HDU
    cf1447D Catching Cheaters
    cf1440 Greedy Shopping
    Treats for the Cows
    dp废物学会了记录路径
    D. Jzzhu and Cities
    cf1359D Yet Another Yet Another Task
    关于sg函数打表的理解
  • 原文地址:https://www.cnblogs.com/ht955/p/14667050.html
Copyright © 2011-2022 走看看