React类型检查
類型檢查
import PropTypes from 'prop-types'類名==List List.propTypes = {list: PropTypes.array } // 默認(rèn)值 List.defaultProps = { list:props:
1.只讀不能修改(不能再賦值表達(dá)式左邊)2.ComponentWillReceiveProp()3.propTypes4. defaultProps5.childrenweb > native
native 需要下載安裝包 // react-router-domweb 直接有的 //react-router-nativenvm
| nvm list available | 查看所有版本 |
| nvm install 版本號(hào) | 下載 |
| nvm list | 列出當(dāng)前可用的包 |
| nvm use 版本號(hào) | 使用哪一個(gè)包 |
| history | 歷史 |
路由模式
Vue使用hash模式 React 使用兩種模式HashRouter # 哈希模式(HashRouter) 錨點(diǎn) 瀏覽器端忽略#(無(wú)法把#及之后帶過(guò)去)browserRouter 路由localhost地址訪問(wèn)地址不存在,進(jìn)行重定向Node起服務(wù)路由
1.下載 react-router-dom2. import {HashRouter as Router,Link,Route,Switch } from ' react-router-dom' 3.<Router></Router> <Switch> //當(dāng)route不給path屬性時(shí)會(huì)匹配任意路由 <Router component={()=><h1>未匹配的路由</h1>}></Router> 無(wú)path匹配任何路由 當(dāng)redirect不給from屬性時(shí)也會(huì)匹配任意路由 <Redirect exact from='/' to='/index'></Redirect> </Switch> Link, //導(dǎo)航標(biāo)簽 to屬性聲明要跳轉(zhuǎn)的路徑 Route,//占位標(biāo)簽,如果path與當(dāng)前路徑一模一樣時(shí)才匹配 Switch // 返回匹配的第一個(gè)路由 exact 表示精準(zhǔn)匹配,當(dāng)path與當(dāng)前路徑一模一樣時(shí)才匹配傳參
1.地址欄傳參 '/index/:id?' 傳遞變量 '/index/10' 傳遞常量 '/index?a=1&b=2' 直接傳遞數(shù)據(jù)Link 標(biāo)簽的to屬性 to={{ pathname:'/cart', data:{a:1,b:2} }} // 在location接收回退版本
window.history.go(-1)window.history.back()透?jìng)?/p> a => b => c b只能接收a的值不能修改a的值
replace
有兩種常見(jiàn)的渲染組件的方式:
component和render。前者是使用React.createElement方法新建一個(gè)元素,而后者僅僅是調(diào)用現(xiàn)有組件的render方法轉(zhuǎn)載于:https://www.cnblogs.com/2oex/p/9569179.html
與50位技術(shù)專家面對(duì)面20年技術(shù)見(jiàn)證,附贈(zèng)技術(shù)全景圖總結(jié)
- 上一篇: 【vue】webpack插件svg-sp
- 下一篇: Struts2.0第三章(文件上传、aj