RN刷新回调

来源:互联网 发布:淘宝店卖肉需要执照吗 编辑:程序博客网 时间:2024/06/07 07:50

有的时候我们需要从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();        }    }