irpas技术客

【taro react】----打包微信小程序后 onShow 多次执行(随着进入页面的次数在不断的累计)_Rattenking_taro onshow

网络 7237

页面子组件 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> ) } } 2. 代码执行结果


1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,会注明原创字样,如未注明都非原创,如有侵权请联系删除!;3.作者投稿可能会经我们编辑修改或补充;4.本站不提供任何储存功能只提供收集或者投稿人的网盘链接。

标签: #taro #onshow #2 #代码执行结果6 #修改后的执行结果页面组件 #执行多次累计执行1 #页面代码2