07 React中条件渲染
React 条件 渲染 07
2023-09-27 14:22:20 时间
17==》 条件渲染 state初始化一般写在构造器当中 CharShop.js如下 import React, { Component } from "react"; export default class CharShop extends Component { // state初始化一般写在构造器当中 constructor(props){ super(props); this.state={ goods: [{ id: 1, text: "web111" }, { id: 2, text: "web222" },{ id: 3, text: "web333" }] } } render(){ // 获取state中的内容 let con = this.state.goods[0].text ? <h1>{this.state.goods[0].text}</h1>:null //条件渲染 return( <div> {con} </div> ) } }
相关文章
- React Native商城项目实战08 - 设置“More”界面cell
- React Native常用第三方库
- 《React官方文档》之Getting Started
- 源码看React 事件机制
- react条件渲染
- react的登录逻辑
- 实战build-react(一)
- React创建组件的三种方式
- 浅谈react无状态组件(哑组件)和有状态组件(智能组件)的区别
- React工程化之PWA之serviceWorker
- create-react-app 脚本搭建工程,修改默认端口号
- React之this.setState方法
- React函数式组件值之useMemo()和useCallback()
- react 的双向数据绑定