Taro 小程序採坑

入口文件的生命週期

生命週期方法 做用 說明
componentWillMount 程序被載入 在微信小程序中這一輩子命週期方法對應 app 的 onLaunch
componentDidMount 程序被載入 在微信小程序中這一輩子命週期方法對應 app 的 onLaunch,在 componentWillMount 後執行
componentDidShow 程序展現出來 在微信小程序中這一輩子命週期方法對應 onShow,在 H5 中一樣實現
componentDidHide 程序被隱藏 在微信小程序中這一輩子命週期方法對應 onHide,在 H5 中一樣實現
componentDidCatchError 錯誤監聽函數 在微信小程序中這一輩子命週期方法對應 onError
componentDidNotFound 頁面不存在監聽函數 在微信小程序中這一輩子命週期方法對應 onPageNotFound

微信小程序中 onLaunch 一般帶有一個參數 options,在 Taro 中你能夠在全部生命週期和普通事件方法中經過 this.$router.params 訪問到 小程序

頁面的生命週期

生命週期方法 做用 說明
componentWillMount 頁面被載入 在微信小程序中這一輩子命週期方法對應 onLoad
componentDidMount 頁面渲染完成 在微信小程序中這一輩子命週期方法對應 onReady
shouldComponentUpdate 頁面是否須要更新
componentWillUpdate 頁面即將更新
componentDidUpdate 頁面更新完畢
componentWillUnmount 頁面退出 在微信小程序中這一輩子命週期方法對應 onUnload
componentDidShow 頁面展現出來 在微信小程序中這一輩子命週期方法對應 onShow,在 H5 中一樣實現
componentDidHide 頁面被隱藏 在微信小程序中這一輩子命週期方法對應 onHide,在 H5 中一樣實現

小程序 navigateBack 返回上一級頁面 componentWillMount 週期再也不執行

未解決... 因爲 navigateBack 的頁面會執行 componentDidShow 因此把請求函數寫在 componentDidShow 這一週期裏 0.0微信小程序

相關文章
相關標籤/搜索