调用 new Component({ target }) 将组件附加到目标,我想用新组件替换目标的所有旧内容。我该怎么做?
最佳答案
如果您正在混合服务器呈现的标记,最好使用 hydrate: true
选项 ( docs here )。
如果 target
之前被 Svelte 组件占用,最好调用该组件的 $destroy()
方法。
否则,最简单的方法就是清空 target
元素:
target.innerHTML = '';
new Component({ target });
https://stackoverflow.com/questions/61640429/
相关文章:
python - 如何聚焦光线或如何在 pygame 中只绘制窗口的某些圆形部分?
c# - 为什么 Visual Studio 不警告我空引用异常?
python - 使用 zip() 对元组列表进行排序时,有时不支持“<”
delphi - 如何在 Delphi 10.3 Rio 上安装 Indy?
arrays - 将 [MLMultiArray] 转换为 Float?
c# - 如何使用 Sustainsys.Saml2 设置 NLog
javascript - AWS Elastic Beanstalk : How to change
azure - 在 Azure 上的资源组之间移动后删除 microsoft.web/certifi