中文亚洲精品无码_熟女乱子伦免费_人人超碰人人爱国产_亚洲熟妇女综合网

當(dāng)前位置: 首頁 > news >正文

wordpress默認(rèn)index百度seo怎么收費(fèi)

wordpress默認(rèn)index,百度seo怎么收費(fèi),威縣做網(wǎng)站哪兒好,網(wǎng)站怎么連接微信支付構(gòu)建組件的方式 函數(shù)式組件(function)createElement(不建議使用)類組件形式創(chuàng)建(不建議使用) 對于 React 的理解 React, 用于構(gòu)建用戶界面的JavaScript庫,本身只提供了Ul層面的解決方案。&am…

構(gòu)建組件的方式

  1. 函數(shù)式組件(function)
  2. createElement(不建議使用)
  3. 類組件形式創(chuàng)建(不建議使用)

對于 React 的理解

React, 用于構(gòu)建用戶界面的JavaScript庫,本身只提供了Ul層面的解決方案。(遵循組件設(shè)計模式、聲明式編程范式和函數(shù)式編程概念,以使前端應(yīng)用程序更高效。)

使用虛擬D0M來有效地操作DOM,遵循從高階組件到低階組件的單向數(shù)據(jù)流。幫助我們將界面成了各個獨(dú)立的小塊,每一個塊就是組件,這些組件之間可以組合、嵌套,構(gòu)成整體頁面,且易于理解和增加可維護(hù)性。

比如類組件,jsx 會被 babel 編譯為合法的 js 語句。被傳入的數(shù)據(jù)可以通過 this.props 在 render() 中訪問。

class HelloMessage extends React.Component {render() {return <div>Hello {this.props.name}</div>;}
}
ReactDOM.render(<HelloMessage name="Taylor" />,document.getElementById("hello-example")
);

react 還有一些特性,jsx 語法、單向數(shù)據(jù)流(react 本身來說 props 只能通過父組件向子組件傳輸,不能反過來修改,便于對數(shù)據(jù)的控制)、虛擬 DOM(diff、patch,高效操作 DOM)、聲明式編程、Component(一切皆為組件)

聲明式編程:關(guān)注要做什么,而不是怎么做,我們可以根據(jù)邏輯的計算聲明要顯示的組件。

比如命令式編程,一步一步描述過程進(jìn)行操作:


const map = new Map.map(document.getElementById("map"), {zoom: 4,center: { lat, lng },
});const marker = new Map.marker({position: { lat, lng },title: "Hello Marker",
});marker.setMap(map);

然后 react 的聲明式編程只需要,聲明出頁面結(jié)構(gòu),然后渲染頁面:

<Map zoom={4} center={(lat, lng)}><Marker position={(lat, lng)} title={"Hello Marker"} />
</Map>

state 和 props

state 用于維護(hù)自身組件的數(shù)據(jù)狀態(tài),setState 用于修改這個數(shù)據(jù)狀態(tài),進(jìn)行更新組件,重新調(diào)用組件的 render 方法;props 用來接收外部(單向數(shù)據(jù)流流,所以一般是父組件)傳過來的數(shù)據(jù)(在子組件內(nèi)為不可變的)。

class Button extends React.Component {constructor() {super();this.state = {count: 0,};}updateCount() {this.setState((prevState, props) => {return { count: prevState.count + 1 };});}render() {return (<button onClick={() => this.updateCount()}>Clicked {this.state.count} times</button>);}
}

setState 還可以接受第二個參數(shù),它是一個函數(shù),會在setState調(diào)用完成并且組件重新渲染之后被調(diào)用,可以用來監(jiān)聽渲染是否完成:

this.setState({name: "JS ",},() => console.log("setState finished")
);

super() 和 super(props) 的區(qū)別

super 代表父類的構(gòu)造函數(shù),子類沒有自己的 this,只能繼承父類的 this 作為自己的 this,所以 super 的調(diào)用必須在constructor 的第一行 。調(diào)用 this ,一般需要傳入 props 作為參數(shù),如果不手動傳入,react 內(nèi)部也會自動傳入 props 。所有無論有沒有 constructor ,render 中都是可以調(diào)用 this.props 的。

使用 super(name) 相當(dāng)于調(diào)用 father.prototype.constructor.call(this.name)

但是也不建議使用super()代替super(props)。因為在 React會在類組件構(gòu)造函數(shù)生成實例后再給 this.props賦值,所以在不傳遞 props在 super的情況下,調(diào)用 this.props 為undefined,如下情況:

class Button extends React.Component {constructor(props) {super(); // propsconsole.log(props); // {}console.log(this.props); // undefined// ...}
}

而傳入props的則都能正常訪問,確保了this.props在構(gòu)造函數(shù)執(zhí)行完畢之前已被賦值,更符合羅輯,如下:

class Button extends React.Component {constructor(props) {super(props); // propsconsole.log(props); // {}console.log(this.props); // {}// ...}
}

對于類組件和函數(shù)組件的理解

  1. 寫法不同
  2. 狀態(tài)管理(setState 、 useState)
  3. 生命周期(函數(shù)組件不存在生命周期,它是使用 useEffect 替代生命周期發(fā)揮作用)
  4. 調(diào)用方法(函數(shù)直接調(diào)用,類實例化后再調(diào)用render方法)
  5. 獲取渲染的值

props 是只讀的,但是 this 是可變的(可以在 render 和生命周期讀取最新值),所以如果組件在請求運(yùn)行時更新,類組件 this.props 可以獲取最新的值,而 函數(shù)組件 props 仍是舊值(函數(shù)組件本身不存在 this)。

// function
function ProfilePage(props) {const showMessage = () => {alert('Followed ' + props.user);}const handleClick = () => {setTimeout(showMessage, 3000);}return (<button onClick={handleClick}>Follow</button>)
}
// class
class ProfilePage extends React.Component {showMessage() {alert('Followed ' + this.props.user);}handleClick() {setTimeout(this.showMessage.bind(this), 3000);}render() {return <button onClick={this.handleClick.bind(this)}>Follow</button>}
}
http://www.risenshineclean.com/news/5096.html

相關(guān)文章:

  • 鄭州hi寶貝網(wǎng)站建設(shè)公司定制網(wǎng)站開發(fā)公司
  • 許昌做網(wǎng)站公司專業(yè)做網(wǎng)站哪家好下載微信
  • 免費(fèi)做封面的網(wǎng)站新聞稿件
  • 建設(shè)校園網(wǎng)站必要性網(wǎng)站營銷網(wǎng)站營銷推廣
  • 左側(cè)導(dǎo)航網(wǎng)站站外推廣方式有哪些
  • 網(wǎng)站數(shù)據(jù)庫怎么做同步網(wǎng)站seo推廣營銷
  • 做磁力網(wǎng)站qq群怎么優(yōu)化排名靠前
  • 甘肅省城鄉(xiāng)住房建設(shè)廳網(wǎng)站首頁快速排名點擊工具
  • 做網(wǎng)站的策劃需要做什么seo免費(fèi)軟件
  • 可信網(wǎng)站辦理今天疫情最新消息
  • 護(hù)膚品網(wǎng)站建設(shè)前的行業(yè)分析營銷軟文怎么寫
  • 網(wǎng)易企業(yè)郵箱怎么發(fā)送文件seo網(wǎng)絡(luò)營銷技巧
  • 唐山企業(yè)建網(wǎng)站山東seo推廣公司
  • 旅游攻略網(wǎng)站開發(fā)龍崗網(wǎng)站設(shè)計
  • 鎮(zhèn)江門戶網(wǎng)站是哪個百度精準(zhǔn)引流推廣
  • 個人設(shè)計網(wǎng)站模板競價托管 微競價
  • 怎么做網(wǎng)站制作網(wǎng)絡(luò)營銷競價推廣
  • 修改網(wǎng)站需要什么凡科建站
  • 企業(yè)手機(jī)端網(wǎng)站設(shè)計模板有域名了怎么建立網(wǎng)站
  • 大豐網(wǎng)站建設(shè)全網(wǎng)推廣軟件
  • 寧波建設(shè)網(wǎng)站價格seo是怎么優(yōu)化推廣的
  • 網(wǎng)站建設(shè)的作用網(wǎng)站流量來源
  • 做游戲下載網(wǎng)站賺錢中央人民政府網(wǎng)
  • 什么網(wǎng)站做設(shè)計可以賺錢搜索引擎營銷是什么
  • 公司在網(wǎng)上做網(wǎng)站怎么做賬怎么注冊網(wǎng)站平臺
  • 無錫網(wǎng)站建設(shè)企業(yè)排名無錫營銷型網(wǎng)站制作
  • 制作網(wǎng)站的策劃方案網(wǎng)站自建
  • 17網(wǎng)站一起做網(wǎng)店不發(fā)貨網(wǎng)上售賣平臺有哪些
  • 做短視頻網(wǎng)站產(chǎn)品營銷方案案例范文
  • 網(wǎng)站怎么做谷歌權(quán)重色盲眼鏡