Arco Design抽屉关闭后怎么自动销毁组件?

柯依🍀 阅读 16

我用 Arco 的 Drawer 组件弹出一个表单,但发现即使关闭了抽屉,里面的组件实例还在内存里,数据也没重置。试过设置 unmountOnClose 为 true,但好像没生效?

这是我的用法:

const [visible, setVisible] = useState(false);

return (
  <>
    <Button onClick={() => setVisible(true)}>打开</Button>
    <Drawer
      visible={visible}
      unmountOnClose={true}
      onClose={() => setVisible(false)}
    >
      <MyFormComponent />
    </Drawer>
  </>
);

是不是哪里写错了?为啥关闭后 MyFormComponent 还没被卸载?

我来解答 赞 4 收藏
二维码
手机扫码查看
1 条解答
书生シ治博
试试看把 unmountOnClose 改成 destroyOnClose,Arco Drawer 的属性名是 destroyOnClose 不是 unmountOnClose,后者是 Ant Design 的写法,Arco 用的是 destroyOnClose

<Drawer
visible={visible}
destroyOnClose={true}
onClose={() => setVisible(false)}
>
<MyFormComponent />
</Drawer>
点赞 2
2026-02-26 09:02