1. <strong id="7actg"></strong>
    2. <table id="7actg"></table>

    3. <address id="7actg"></address>
      <address id="7actg"></address>
      1. <object id="7actg"><tt id="7actg"></tt></object>

        react-statements小巧可嵌套的 React 語句控制組件

        聯(lián)合創(chuàng)作 · 2023-09-22 02:46

        react-statements是一個很小的React語句控制組件,更漂亮的條件渲染方法。

        安裝

        npm i --save react-statements
        yarn add react-statements

        栗子

        import { If } from 'react-statements'class Example extends React.Component {
          constructor(props) {
            super(props);    this.state = {logic: true};
          }
          render() {    return (      <div>
                <If when={this.state.logic}>
                  <p>我是一些組件內(nèi)容</p>
                </If>
              </div>
            );
          }
        }

        文檔說明

        If 組件

        If組件可以使用一個when屬性來控制組件是否渲染

        <If when={condition}>
          <p>when在轉(zhuǎn)為bool為true的條件下顯示這個組件</p>
        </If>
        
        <If when={condition} children={<p>使用方法同上,單標簽方法中使用</p>} />

        Switch 組件

        Switch組件可以根據(jù)指定的值渲染不同的組件

        Switch組件內(nèi)部使用Case組件對不同的值進行判斷

        Switch組件內(nèi)部同時可以使用Default來設(shè)置一個默認顯示組件

        <Switch value={value}>
          <Case when={condition}>
            <p>condition 1</p>
          </Case>
          <Case when={condition}>
            <p>condition 2</p>
          </Case>
          <Case when='c' children={<p>condition 3</p>}/>
          <Default children={<p>默認組件</p>}/>
        </Switch>

        For

        For組件可以對Array、Object遍歷生成一組組件

        For組件內(nèi)部也可以使用Default來顯示默認組件

        <For of={['a', 'b', 'c']}>
          {(item, index) => (<p key={index}>{index}:{item}</p>)}  <Default>默認組件</Default></For>
        瀏覽 6
        點贊
        評論
        收藏
        分享

        手機掃一掃分享

        編輯 分享
        舉報
        評論
        圖片
        表情
        推薦
        點贊
        評論
        收藏
        分享

        手機掃一掃分享

        編輯 分享
        舉報
        1. <strong id="7actg"></strong>
        2. <table id="7actg"></table>

        3. <address id="7actg"></address>
          <address id="7actg"></address>
          1. <object id="7actg"><tt id="7actg"></tt></object>
            国产精品嫩草69夜色69夜色 | 强壮的公次次弄得美女高潮电影 | 91成人 在线观看学生 | 摸进她的内裤里疯狂揉她公交车 | 欧洲色色| 免费污污视频网站 | 做爰过程很黄口述 | 深爱激情婷婷综合基地 | 一级a一级a爱片免费兔兔软件丶 | 国产成人 免费视频在线观看 |