react 操作元件上的屬性

2022-08-17 23:54:16 字數 564 閱讀 8572

import react from 'react';

var arr = [

,,];class component1 extends react.component

}//匯出元件

export default component1;

import react from 'react';

import reactdom from 'react-dom';

import component1 from './components/component1.jsx';

reactdom.render(

,document.getelementbyid('content')

);

輸出:hello john

元件的屬性可以在元件類的 this.props 物件上獲取

比如 name 屬性就可以通過 this.props.name 讀取

此外每個組建只能擁有乙個頂層標籤

React元件屬性類 propTypes

可以宣告 prop 為指定的 js 基本型別。預設 情況下,這些 prop 都是可傳可不傳的。optionalarray react.proptypes.array,optionalbool react.proptypes.bool,optionalfunc react.proptypes.func...

React元件通訊 REF屬性

乙個 ref 例項在建構函式中建立,並賦值給 this.firstref this.firstref react.createref 等同於 在 render 方法內部,將建構函式中建立的 ref 傳遞給 div 處理dom元素 this.firstref.current dom元素.this.例項...

react 上拉載入元件的使用

移動端前端需要實現分頁功能,與傳統的pc端分頁不同,決定使用螞蟻的長列表元件,支援上拉載入及下拉重新整理 本文只涉及上拉載入 引入元件 1importfrom antd mobile 定義一些初始狀態 12 3456 78910 1112 1314 1516 17constructor this.s...