【发布时间】:2020-10-25 05:19:47
【问题描述】:
在 React 中,您可以使用 Portals 在不同的节点中渲染组件:
ReactDOM.createPortal(
<Component />,
document.getElementById('id')
);
使用 portal-vue 包的 Vue 也是如此。
但是在 Svelte 中是否有类似的方法?
<body>
<Header>
<Modal /> <!-- Modal is rendered here -->
</Header>
<!-- But the Modal DOM would be injected at the body end -->
</body>
【问题讨论】:
-
仅供参考 这个问题的一般答案是只使用 DOM 方法,就像没有任何框架一样。由于 Svelte 不使用虚拟 DOM(与 React 或 Vue 不同),因此您实际上并不需要“门户”:)
标签: javascript svelte