在react中实现keepAlive的插件

2021-11-10  本文已影响0人  jack_rofer
  1. react-activation
  2. 官方中文文档

实例:

背景:需要缓存一个页面的状态(因为想保留该页面内某些步骤切换的状态)
技术: umi^3.3.7、react17.x
实现:

  1. 安装
npm install react-activation@^0.94 uuid@^8.3.2 umi-plugin-keep-alive@0.0.1-beta.26

2.在该页面引入

import { KeepAlive } from react-activation

const TestPage = () => {
  return <div></div>
}

export default () => (
  <KeepAlive name="/TestPage.html" saveScrollPosition="screen">
    <TestPage/>
  </KeepAlive>
)
上一篇 下一篇

猜你喜欢

热点阅读