页面子组件 onShow 执行多次【累计执行】
1. 出现问题的代码
test.jsx 测试组件代码
import React, { Component } from 'react'
import { View } from '@tarojs/components'
import { eventCenter, getCurrentInstance } from '@tarojs/taro'
export default class RuiPoster extends Component {
constructor(props) {
super(props)
}
state = {
count: 0
}
$instance = getCurrentInstance();
componentDidMount(){
const onShowEventId = this.$instance.router.onShow;
eventCenter.on(onShowEventId, this.onShow);
}
onShow = () => {
console.log('进入页面第几次:',++this.state.count)
console.log('onshow', +new Date())
}
render () {
return (
<View>
</View>
)
}
}