I'm using Vue 3's teleport to render an element into a div and it works as expected.
Teleport will add the item to the selected element but will not replace the current element in the div.
How do I set up the teleport to replace elements within the div, similar to how a vue application replaces the content of an anchor div when mounted?
Background: For SEO reasons, I need placeholder elements until the app renders and delivers.
<!-- 应用程序外部的HTML --> <div> <div id="teleport-here">传送占位符...我希望这个被传送组件替换</div> <div id="app">当应用程序挂载时,这个占位符将被应用程序替换...</div> </div> <!-- 传送组件 --> <teleport to="#telport-here"> <div>传送内容...</div> </teleport>
You need to have some separate logic to remove placeholders when necessary.
Set the content of the placeholder to empty in
setup
: