Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.3k views
in Technique[技术] by (71.8m points)

taro小程序

请问下taro开发小程序的过程中,子组件中的componentDidShow生命周期方法没有被执行,这个应该怎么解决呢

// 父组件代码如下
export default class Index extends Component {

componentWillMount () { }

componentDidMount () { }

componentWillUnmount () { }

componentDidShow () {

console.log('yyyyyyyyyyyy')

}

componentDidHide () { }

render () {

return (
  <View className='index'>
    <Test></Test>
    <Text>Hello world!</Text>
  </View>
)

}
}

// 子组件代码如下
export class Test extends Component {
componentWillMount() { }

componentDidMount() { }

componentWillUnmount() { }

componentDidShow() {

console.log('xxxxxxxxxxxxxxshow')

}

componentDidHide() { }

render() {

return (
  <View>测试</View>
)

}
}


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

情况一,看下这个链接有关子组件componentDidShow不执行的原因 https://github.com/NervJS/tar...

image.png
排查下是不是微信开发工具基础库版本低

情况二,子组件的 componentDidShow 是跟随页面的 componentDidShow 的,所以组件动态切换是不会触发组件的 componentDidShow,你应该用子组件的 componentWillRecieveProps


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...