当前位置:网站首页>【二】通过props进行传值,子页面多种方式接收
【二】通过props进行传值,子页面多种方式接收
2022-08-02 16:12:00 【编程小橙子】

image.png
先看效果图

image.png
使用常用的三种方式接收父页面传递过来的数据
Props.js
// import React, { Component } from 'react';
// 方式一:接收父页面传递的数据
// export default class Props extends Component {
// render() {
// return <div>{this.props.title}</div>;
// }
// }
import React from 'react';
//方式二:接收父页面传递的数据
// export default function Props(props) {
// return <div>{props.title}</div>;
// }
// 方式三:接收参数的解构
export default function Props({ title }) {
return <div>{title}</div>;
}
App.js
import React, { Component } from 'react';
import Props from './Props';
export default class App extends Component {
render() {
return (
<div>
<Props title="这是一个字符串"></Props>
</div>
);
}
}
本次就分享到这里,喜欢的请关注支持下,后期会带来更多丰富的内容
边栏推荐
猜你喜欢
随机推荐
uniapp 小程序 动态style class
Locking and Concurrency Control (4)
Number 类及各子类所占字节数源码分析
JZ4 二维数组中的查找
从Oracle日志解析学习数据库内核原理
julia系列6:并行计算
NC231 只出现一次的数字
JZ21 调整数组顺序使奇数位于偶数前面(一)-相对位置变化
JZ69 跳台阶
技术分享| 融合调度系统中的电子围栏功能说明
QueryWrapper method explained
【[SCOI2005] 互不侵犯】【状压DP(含概念讲解)】
机械臂速成小指南(十五):线性规划
如何为项目匹配资源技能和要求?
Coordinate knowledge in digital twin campus scenarios
Limit实现分页
Redis进阶之路:深度解析Redis单线程架构,图文并茂不能再清晰了
时间戳格式化「建议收藏」
解析并执行 shell 命令
融云「 IM 进阶实战高手课」系列直播上线