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

一块钱购物网站市场调研方法

一块钱购物网站,市场调研方法,厦门商城网站建设,php 微网站开发自定义组件的时候往往需要传 children,由于写法比较多样,我就总结了一下。 方案列表 1. 类组件1.1 类组件,不使用解构1.2 类组件,使用解构 2. 函数组件2.1 函数组件,不使用解构2.2 函数组件,外部解构2.3 函…

自定义组件的时候往往需要传 children,由于写法比较多样,我就总结了一下。

方案列表

  • 1. 类组件
    • 1.1 类组件,不使用解构
    • 1.2 类组件,使用解构
  • 2. 函数组件
    • 2.1 函数组件,不使用解构
    • 2.2 函数组件,外部解构
    • 2.3 函数组件,内部解构
  • 3. 普通函数
    • 3.1 普通函数,内部解构
    • 3.2 普通函数,外部解构
    • 3.3 普通函数,外部解构,不使用自定义Type
    • 3.4 普通函数,不使用解构,不使用自定义Type
  • 调用及展示


要自定义的组件是这样的:

在这里插入图片描述

其中包含一个 title 和一个 children

定义一个后面要用到的 Props:

/** 定义属性对象* - title: 标题* - children: 子组件*/
type Props = {title: string;children?: React.ReactNode;
};

1. 类组件

1.1 类组件,不使用解构

class ClassComponent1 extends Component<Props> {render(): ReactNode {return (<div style={{ backgroundColor: 'red' }}><h2>{this.props.title}</h2>{this.props.children}</div>);}
}

1.2 类组件,使用解构

class ClassComponent2 extends Component<Props> {render(): ReactNode {// 解构赋值const { title, children } = this.props;return (<div style={{ backgroundColor: 'red' }}><h2>{title}</h2>{children}</div>);}
}

2. 函数组件

2.1 函数组件,不使用解构

const FunctionComponent1: React.FC<Props> = (props) => {return (<div style={{ backgroundColor: 'orange' }}><h2>{props.title}</h2>{props.children}</div>);
};

2.2 函数组件,外部解构

const FunctionComponent2: React.FC<Props> = ({ title, children }) => {return (<div style={{ backgroundColor: 'orange' }}><h2>{title}</h2>{children}</div>);
};

2.3 函数组件,内部解构

const FunctionComponent3: React.FC<Props> = (props) => {// 解构赋值const { title, children } = props;return (<div style={{ backgroundColor: 'orange' }}><h2>{title}</h2>{children}</div>);
};

3. 普通函数

3.1 普通函数,内部解构

function NormalFunction1(props: Props) {// 解构赋值const { title, children } = props;return (<div style={{ backgroundColor: 'yellow' }}><h2>{title}</h2>{children}</div>);
}

3.2 普通函数,外部解构

function NormalFunction2({ title, children }: Props) {return (<div style={{ backgroundColor: 'yellow' }}><h2>{title}</h2>{children}</div>);
}

3.3 普通函数,外部解构,不使用自定义Type

function NormalFunction3({title,children,
}: {title: string;children?: React.ReactNode;
}) {return (<div style={{ backgroundColor: 'yellow' }}><h2>{title}</h2>{children}</div>);
}

3.4 普通函数,不使用解构,不使用自定义Type

function NormalFunction4(props: { title: string; children?: React.ReactNode }) {return (<div style={{ backgroundColor: 'yellow' }}><h2>{props.title}</h2>{props.children}</div>);
}

调用及展示

export default class ChildrenPage extends Component {render() {return (<div style={{ padding: '20px' }}><h1>组件传children</h1><ClassComponent1 title="类组件,不使用解构"><p>这里是children</p></ClassComponent1><ClassComponent2 title="类组件,使用解构"><p>这里是children</p></ClassComponent2><FunctionComponent1 title="函数组件,不使用解构"><p>这是里children</p></FunctionComponent1><FunctionComponent2 title="函数组件,外部解构"><p>这是里children</p></FunctionComponent2><FunctionComponent3 title="函数组件,内部解构"><p>这是里children</p></FunctionComponent3><NormalFunction1 title="普通函数,内部解构"><p>这里是children</p></NormalFunction1><NormalFunction2 title="普通函数,外部解构"><p>这里是children</p></NormalFunction2><NormalFunction3 title="普通函数,外部解构,不使用自定义Type"><p>这里是children</p></NormalFunction3><NormalFunction4 title="普通函数,不使用解构,不使用自定义Type"><p>这里是children</p></NormalFunction4></div>);}
}

在这里插入图片描述

http://www.yidumall.com/news/44940.html

相关文章:

  • 防城港做网站的聊石家庄seo
  • wordpress媒体库备份广东百度seo
  • 有哪些网站做美食的图片很精致充电宝seo关键词优化
  • 高端做网站公司哪家好怎么投放广告
  • 信息空间网站好app开发用什么软件
  • pb代做网站网络项目发布网
  • 打开百度网站建设seo工具在线访问
  • 服务器可以备案别人的域名吗合肥网站seo
  • 东莞网站托管如何进行新产品的推广
  • 向搜索引擎提交网站营销型网站建设费用
  • 手机泉州网seo常见优化技术
  • 网站与网站做外链好吗seo优化网站推广全域营销获客公司
  • 如何提升网站的搜索排名平台app如何推广
  • 网站为什么要做seo开个网站平台要多少钱
  • 广州网站定制什么样的人适合做营销
  • 网站后台维护怎么做北京建站工作室
  • java新闻网站开发营销策略都有哪些方面
  • 网站开发测试工程师网络营销企业网站优化
  • 郑州市城乡建设局官网在线seo关键词排名优化
  • 网页制作怎么做多个网站杭州网站优化搜索
  • 古董做推广哪个网站好如何推广品牌知名度
  • 游戏是怎么做的视频网站百度推广怎么收费标准
  • 日照营销型网站建设seo具体seo怎么优化
  • 易企秀h5长页面制作成都市seo网站公司
  • 手机网站模板案例百度最怕哪个投诉电话
  • 网站的360快照怎么做谈谈你对seo概念的理解
  • 怎么做贝店式的网站淘宝seo排名优化
  • 北京电商网站开发公司江西网络推广seo
  • 网站cms系统 开源网站推广的策略
  • 拱墅区做网站重庆百度推广开户