配合dva插件一起使用的时候,dispatch更新state时,页面没有更新,切换才能更新视图
ZmSama opened this issue · comments
ZmSama commented
CJY commented
给个 demo 吧,没用过 dva
ZmSama commented
我把这个手里的demo上传到码云去,然后给你看看,我已经搭建好环境了,你直接测试即可,就在那个客户的界面,在连接函数那里,你注释KeepAlive测试一下可以更新视图,放开注释就不行了
这是仓库地址:
https://gitee.com/liao_zi_mo/demo-keep-alive-test.git
------------------ 原始邮件 ------------------
发件人: "alitajs/umi-plugin-keep-alive" ***@***.***>;
发送时间: 2022年2月25日(星期五) 上午9:40
***@***.***>;
***@***.******@***.***>;
主题: Re: [alitajs/umi-plugin-keep-alive] 配合dva插件一起使用的时候,dispatch更新state时,页面没有更新,切换才能更新视图 (Issue #60)
给个 demo 吧,没用过 dva
—
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications on the go with GitHub Mobile for iOS or Android.
You are receiving this because you authored the thread.Message ID: ***@***.***>
CMG-GG commented
缓存的时候要缓存组件,而models里面的数据不能缓存,不然就出现,实际执行代码,而页面没有更新。
所以要对connect这里改造一下,缓存一个组件,这个组件再connectmodels
//connect导出一个组件,里面的props是自己获取的,不会被缓存住
const UserInfo = connect(({ __login,}) => ({
__login,
}))(UserInfoIndex);
class UserInfoKeep extends PureComponent {
constructor(props) {
super(props);
this.state = {};
}
render() {
return (
<KeepAlive>
// UserInfo被缓存了
<UserInfo />
</KeepAlive>
);
}
}
// 最终导出被缓存的组件
export default connect()(UserInfoKeep);