RN刷新回调

有的时候我们需要从A进入B,然后B返回到A,A同时也需要刷新

A的代码(在进入B时传入刷新要用到的函数)

goGouWu() {
        //alert('点击了去购物车');
        const { navigator } = this.props;
        //为什么这里可以取得 props.navigator?请看上文:
        //<Component {...route.params} navigator={navigator} />
        //这里传递了navigator作为props
        let _that=this;
        if (navigator) {
            navigator.push({
                name: 'GouWu',
                component: GouWu,
                params: {

                    fetchData: function () {

                        console.log('启动fetchData里的方法了');

                        AsyncStorage.clear(function (err) {
                            if (!err) {
                                _that.setState({
                                    count: 0,
                                });

                                alert('购物车已经清空');
                            }
                        });

                    }
                }

            })
        }
    }

B再返回之前先调用刷新函数

clearStorage() {
        //触发一下回调 让数据同步
        console.log('点击了清空购物车');
        if (this.props.fetchData) {
            console.log('点击了清空购物车----回调去影响List页面');
            this.props.fetchData();

        }

        const { navigator } = this.props;
        if (navigator) {
            navigator.pop();
        }
    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值