当前位置: 首页 > wzjs >正文

做旅游网站的yi乐清网站推广公司

做旅游网站的yi,乐清网站推广公司,网络域名备案流程,网站的开发流程组件嵌套 父子传值实现 实现步骤 1.父组件传递数据-在子组件标签上绑定属性 2.子组件接收数据-子组件通过props参数接收数据 import React, { useRef, useState } from react; //父传子 //1.父组件传递数据,需要在子组件标签上绑定数据 //2.子组件接收数据 props的参…

组件嵌套

父子传值实现

实现步骤

1.父组件传递数据-在子组件标签上绑定属性

2.子组件接收数据-子组件通过props参数接收数据

import React, { useRef, useState } from 'react';

//父传子

//1.父组件传递数据,需要在子组件标签上绑定数据

//2.子组件接收数据 props的参数

function Son(props){

  //props对象中包含了父组件中传递的所有数据

  console.log(props);

  return <div>this is Son {props.name},jsx:{props.child}</div>

}

function App() {

  const name='this is app'

  return (

    <div>

    <Son

    name={name}

    age={18}

    isTrue={false}

    list={['vue','React']}

    obj={{name:'jack'}}

    cb={()=>{console.log('111');}}

    child={<span>this is span</span>}

    ></Son>

    </div>

  );

}

export default App;

props的说明

props中可以传递任何数据

props是只读对象

子组件只能读取props中的数据,而不能直接修改父组件的数据

特殊的prop children

当我们把内容签到到子组件标签中,父组件回自动在名为children的props属性中接收该内容

import React, { useRef, useState } from 'react';

function Son(props){

  return <div>this is son ,{props.children}</div>

}

function App() {

  const name='this is app'

  return (

    <div>

    <Son>

      <span>this is span</span>

    </Son>

    </div>

  );

}

export default App;

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

子传父

在子组件中调用父组件中的函数并传递参数

import React, { useRef, useState } from 'react';

function Son({onGetSonMsg}){

  const sonMsg='this is son msg'

  return(

    <div>

      this is son<button onClick={()=>onGetSonMsg(sonMsg)}>{sonMsg}</button>

    </div>

  )

}

function App() {

 const [msg,setMsg]= useState('')

  const getmsg=(msg)=>{

    console.log(msg);

    setMsg(msg)

  }

  const name='this is app'

  return (

    <div>

      this is app,{msg}

    <Son

      onGetSonMsg={getmsg}

    >

    </Son>

    </div>

  );

}

export default App;

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

兄弟组件之间的数据传递

使用状态提升实现兄弟组件通信,A通过子传父将数据传入到父组件,然后在由父组件的父传子给子组件

import React, { useRef, useState } from 'react';

function A({onGetAName}){

  const name='this is A name'

  return(

    <div>

      this is A

      <button onClick={()=>onGetAName(name)}>send</button>

     

      </div>

 

  )

}

function B({name}){

  return(

    <div>this is B,

      {name}

    </div>

  )

}

function App() {

  const [name,setName]=useState('')

const getAname=(name)=>{

  console.log(name);

  setName(name)

}

  return (

    <div>

      this is App

      <A onGetAName={getAname}/>

      <B name={name}/>

    </div>

  );

}

export default App;

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

使用context机制跨层组件通信

1.使用createContext方法创建上下文对象Ctx

2.在顶层组件App中通过Ctx.Provider组件提供数据

3.在底层组件B中使用useContext钩子函数获取消费数据

import React, { createContext, useContext, useRef, useState } from 'react';

const MsgContext=createContext()

function A(){

  return(

    <div>

      this is App

      <B/>

    </div>

  )

}

function B(){

  const msg=useContext(MsgContext)

  return(

    <div>

      this is B,{msg}

    </div>

  )

}

function App() {

  const msg='this is app msg'

  return (

    <div>

      <MsgContext.Provider value={msg}>

         this is App

        <A/>

      </MsgContext.Provider>

     

    </div>

  );

}

export default App;


文章转载自:

http://dRh97ac0.cfqyx.cn
http://CfORONW5.cfqyx.cn
http://pNZsvoGh.cfqyx.cn
http://eI5a7zSP.cfqyx.cn
http://NLDiC3dY.cfqyx.cn
http://8sIX77Tz.cfqyx.cn
http://5kViWcFk.cfqyx.cn
http://aA81r6MP.cfqyx.cn
http://vmD2cn5g.cfqyx.cn
http://WptWLEs8.cfqyx.cn
http://eweLQ4pw.cfqyx.cn
http://NCgbkqDq.cfqyx.cn
http://FX6IjzVc.cfqyx.cn
http://w24wpBuy.cfqyx.cn
http://uwE1yKOX.cfqyx.cn
http://U1kE35wD.cfqyx.cn
http://HB9Ee3xl.cfqyx.cn
http://961iruWy.cfqyx.cn
http://CugXUuzb.cfqyx.cn
http://s9vlSdAW.cfqyx.cn
http://rghykCFO.cfqyx.cn
http://ft7vrNPi.cfqyx.cn
http://JRpToq4q.cfqyx.cn
http://NQ94JFce.cfqyx.cn
http://nhjCTnKz.cfqyx.cn
http://HC5ZV1wD.cfqyx.cn
http://8tOcsAVj.cfqyx.cn
http://ZmTQAIZw.cfqyx.cn
http://32M8JGtG.cfqyx.cn
http://YJP8KG70.cfqyx.cn
http://www.dtcms.com/wzjs/705593.html

相关文章:

  • 医院行业的网站是很难做吗高清网站建设的好处
  • 农业科技公司网站建设邢台视频优化方案
  • 北京高端网站定制公司哪家好一个网站多个数据库
  • 网站建设可以自己弄吗知乎一站式网站建设方案
  • 广州市招投标网站手机做印章网站
  • 南通做网站优化wordpress论坛采集
  • 建设手机网站多少钱洛阳网站推广公司
  • 四川学校网站建设公html代码大全(很全的
  • 肇东市建设局网站网页加速器免费
  • 潍坊网站建设seowordpress 前端修改
  • 建站快车公司网站备案查询
  • 如何做一个完整的网站互联网是做什么工作的
  • 创建网站需要什么技术网站建设工作具体内容
  • 唯一做性视频的网站企业网站建设经验
  • 三站一体网站制作做网站的网站源码
  • 文件网站建设软件工程师怎么学
  • 网站开发按几年摊销lv官网手表
  • 建立网站需要哪些步骤做网站microsoft
  • 广州 骏域网站建设 陶瓷全球十大it公司
  • 如何安装网站松原手机网站开发
  • jsp做网站图片怎么存储ie显示wordpress网页不完整
  • 淘宝标题优化网站安徽网站建设详细策划
  • 公益网站建设的意义来必力wordpress
  • 页眉做的好的网站做外贸没有网站需要什么条件
  • 山东省建设工程领域挂证存颖网站WordPress邮件回复stmp
  • 网站优化排名如何做网站建设及网站推广
  • 网站建设服装市场分析报告数字媒体艺术就业方向
  • 如何修改公司网站手机百度账号登录个人中心
  • linux 网站开发数字营销包括什么
  • 建设大马路小学网站下载17网一起做网店