Javascript 在Svelte中实现门户
在React中,可以使用以下命令在不同节点中渲染组件:Javascript 在Svelte中实现门户,javascript,svelte,Javascript,Svelte,在React中,可以使用以下命令在不同节点中渲染组件: ReactDOM.createPortal( , document.getElementById('id')) ); 使用该软件包的Vue也是如此 但是有没有一种方法可以让苗条的身材变得更苗条呢 请参阅本期: 门户网站 从“svelte”导入{onMount,onDestroy} 让参考 让门户 onMount(()=>{ portal=document.createElement('div') portal.className='p
ReactDOM.createPortal(
,
document.getElementById('id'))
);
使用该软件包的Vue也是如此
但是有没有一种方法可以让苗条的身材变得更苗条呢
请参阅本期:
门户网站
从“svelte”导入{onMount,onDestroy}
让参考
让门户
onMount(()=>{
portal=document.createElement('div')
portal.className='portal'
document.body.appendChild(门户)
portal.appendChild(参考)
})
onDestroy(()=>{
document.body.removeChild(门户)
})
.portal克隆{显示:无;}
然后,您可以使用以下模板进行编辑。模态将在
下显示:
一种解决方案是使用库:
进口 门户 从…起 '苗条门户';
这些示例使用了Svelte actions,这是另一种不需要组件但增强了现有组件的方法:-仅供参考,这个问题的一般答案是只使用DOM方法,就像不使用任何框架一样。由于Svelte不使用虚拟DOM(与React或Vue不同),因此您实际上不需要“门户”: