react 父元件傳遞函式給子元件

2021-08-30 13:24:08 字數 1676 閱讀 6209

學習react過程中向把lits列表中的item項抽象成乙個元件,子元件內部有個swipeaction元件,它需要接受乙個物件,物件中包含乙個自定義函式,不是直接通過props傳遞的函式;這就有點暈了,不知道jsx能否找到函式的所屬物件,特此做了相關記錄

// 通過高階函式返回定義的事件,高階函式獲取變數引數,在返回函式中獲取事件物件

deletegoodsbyidbypost

(goodsid, index)

) goodsservice.

deletegoodsbyidbypost

(goodsid)

.then

(function

(res)})

;}render()

>錄入<

/link>

;return

(>,}

];let url =

"/goodsmanage/goodsdetailsupdate/"

+currentobj.goodsid;

return

(url=

goodsobj=

rightswipeconfigarray=

>

<

/goodslistitemcomp>);

})}<

/div>

<

/div>);

}import basecomponent from

'../core/basecomponent.js'

;import

from

'antd-mobile'

;import

from

'react-router-dom'

;/**

* 商品列表的 item 項元件

}>售價: 元<

/div>

}>

<

/div>

<

/div>

<

/div>

<

/link>

<

/swipeaction>);

}}export

default goodslistitemcomp;

swipeaction 的屬性right 定義的方法,最終還是來自父元件傳遞過來的,方法中的this是指向的父元件

react 子元件傳遞資料給父元件

第一種 通過定義函式實現 1 父元件設定含有this.setstate 的方法,形參為接收子元件的變數 2 將方法作為引數傳遞給子元件 如3 子元件通過this.props.鍵名接收函式 this.props.鍵名 子元件的資料 第二種 通過父元素傳遞的函式在標籤中通過箭頭函式,直接傳參 如 示例 ...

react 子元件和父元件之間傳遞值

react元件之間傳遞值,其實和angular的output input類似,他用的是屬性來傳遞的props,父 子 在父元件中引用子元件的時候,設定屬性即可,然後在子元件中 通過 this.props.name就可以獲取。子 父 子元件中呼叫,父元件中定義的屬性 方法 將引數傳遞獲取。如圖,子元件...

react 父元件傳值子元件,子元件傳值孫元件

import react from react import reacttypes from prop types 最外層的父元件 export default class com1 extends react.component render 中間的子元件 class com2 extends r...