React踩坑:TypeError Cannot read property props of undefined

錯誤:點擊按鈕以後想要視情況跳轉頁面,但是用this.props.history.push()的時候報錯TypeError: Cannot read property ‘props’ of undefined 錯誤原因:沒有給函數綁定this,函數內部引用this的時候無法解析出this,也就得不到this的屬性props了。 解決方法:在組件的構造函數constructor中添加: this.函
相關文章
相關標籤/搜索