svelte

Implement a portal in Svelte

*爱你&永不变心* 提交于 2020-12-06 12:22:18
问题 In React you can render a component in a different node using Portals: ReactDOM.createPortal( <Component />, document.getElementById('id') ); Same for Vue using the portal-vue package. But is there a way to something similar in Svelte? <body> <Header> <Modal /> <!-- Modal is rendered here --> </Header> <!-- But the Modal DOM would be injected at the body end --> </body> 回答1: See this issue : https://github.com/sveltejs/svelte/issues/3088 Portal.svelte <script> import { onMount, onDestroy }