参考:https://blog.csdn.net/weixin_38201500/article/details/105764549
1.版本 :taro@3.0.7
2.代码:
timeloop = null;
componentDidShow = async () => {
this.timeloop = setInterval(() => {
messNum();
}, 60000);
}
componentDidHide = () => {
clearInterval(this.timeloop);
};
3.在我当前所进行的taro小程序中,componentWillUnmount()不会被触发,用的也是react框架;猜想是小程序页面不会被卸载掉,它们只是被隐藏掉了,也就是页面切入前台/后台
4.生命周期:
componentDidShow()
//页面显示/切入前台时触发
componentDidHide()
//页面隐藏/切入后台时触发, 如 navigateTo 或底部 tab 切换到其他页面,小程序切入后台等
componentDidMount()
//页面初次渲染完成时触发,一个页面只会调用一次,代表页面已经准备妥当,可以和视图层进行交互
componentWillUnmount()
//页面卸载时触发,如 redirectTo 或 navigateBack 到其他页面时