React Webapp(二)-項目開發(fā)

https://segmentfault.com/a/1190000011474522
這個學(xué)習(xí)redux很有用

輪播用 react-slick組件

插件的css樣式是在index.html中引入的

$npm install react-slick
<ins>標(biāo)簽語義:被插入的文本</ins>
<del>標(biāo)簽語義:被刪除的文本</del>
map函數(shù)中返回多嵌套標(biāo)簽時,return要加()
{
      data.map(item=>{
          return (
              <div>
                    <span></span>
              </div>
                  )
        })
}
map組件嵌套可以這么寫:
{
      data.map(item=>{
          return <LikeList key={item.id} data={item}> </LikeList>
        })
}

LikeList 組件

class LikeList  extendes Component{
    render(){
        const { id,name,img,age } = this.props.data;
        return (
              ...
        )
      }
}
下拉刷新:8-6

這個圖???


image.png

首頁中的兩個模塊“猜你喜歡”和“超值特惠”,分別寫了倆個reducer(state,action)然后合并


image.png

表單阻攔:

         <form action="">
                <Prompt
                    when={isBlocking}
                    message={location =>
                        `Are you sure you want to go to ${location.pathname}`
                    }
                />
            </form>

當(dāng)isBlocking為true的時候,再進(jìn)行路由跳轉(zhuǎn)時會彈出message里面的對話內(nèi)容

<Switch>
          <Route path="/" exact component={Home} />
          <Redirect from="/old-match" to="/will-match" />
          <Route path="/will-match" component={WillMatch} />
          <Route component={NoMatch} />
        </Switch>

路由點擊從/old-match——will-match跳轉(zhuǎn)時,頁面不發(fā)生變化

 previousLocation = this.props.location;
   return (
      <div>
        <Switch location={isModal ? this.previousLocation : location}>
          <Route exact path="/" component={Home} />
          <Route path="/gallery" component={Gallery} />
          <Route path="/img/:id" component={ImageView} />
        </Switch>
        {isModal ? <Route path="/img/:id" component={Modal} /> : null}
      </div>
    );

isModal 為假的時候,顯示switch中的某一個對應(yīng)Route,它去匹配的路由頁面是從Switch本location中去找的。當(dāng)isModal 為真的時候匹配的路由頁面是從整個父級render去找,所以匹配到的是: {isModal ? <Route path="/img/:id" component={Modal} /> : null}這個Route

  return (
    <div
      style={{
        width: 50,
        height: 50,
        background: color
      }}
    />
  );

動態(tài)style是這么寫的

this.props.location.pathname

獲取當(dāng)前路徑


image.png

switch用法注意了,因為/second是可以同時匹配/和/second的,以至于它匹配到第一個是時候就懶得往下找了,如果是這倆個Route換一下位置就能解決,但是總不能老是換位置解決,所以用"extra"它的中文翻譯是:“精確”,只匹配和path完全匹配的路由。

<Route  path={ `${match.path}/edit/:editid` } exact component={EditTable}></Route>

input表單寫法:

  inputchange(e){
        this.setState({id_:e.target.value})
    }
<input type="text" value={id_} onChange={this.inputchange.bind(this)}/>

還可以直接這么寫:

<input type="text" value={id_} onChange={e=>{this.setState({id_:e.target.value})}}/>

寫table的reducer

import {handleActions} from 'redux-actions'

const initialState = {

}

const tableReducer = handleActions({

},initialState)

export { tableReducer as default }
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 前言 react-router針對不同的使用場景衍生了不同的路由包,RN項目用react-router-nativ...
    大柚子08閱讀 36,665評論 5 39
  • React Router教程 React項目的可用的路由庫是React-Router,當(dāng)然這也是官方支持的。它也分...
    IT老馬閱讀 59,274評論 0 49
  • React-Router v4 1. 設(shè)計理念1.1. 動態(tài)路由1.2. 嵌套路由1.3. 響應(yīng)式路由 2. 快速...
    wlszouc閱讀 8,703評論 0 14
  • 內(nèi)容: 1. 運算符作用位置的說明 如何做到在左側(cè),中間還是右側(cè)執(zhí)行呢? 前置運算符:prefix 后置運算符:p...
    Mccc_閱讀 1,914評論 0 2
  • github 之所以要使用git或者github,確實是因為它作為一個分布式的儲存?zhèn)}庫極其方便,每次的記錄統(tǒng)統(tǒng)保存...
    Amy_Cui閱讀 821評論 0 3

友情鏈接更多精彩內(nèi)容