您的位置:首页 > 科技 > 能源 > 山东省政府办公厅综合处处长_设计网站无锡_2023新闻摘抄十条_蚁百杭州网站seo优化

山东省政府办公厅综合处处长_设计网站无锡_2023新闻摘抄十条_蚁百杭州网站seo优化

2024/9/29 8:16:58 来源:https://blog.csdn.net/weixin_44166849/article/details/142611258  浏览:    关键词:山东省政府办公厅综合处处长_设计网站无锡_2023新闻摘抄十条_蚁百杭州网站seo优化
山东省政府办公厅综合处处长_设计网站无锡_2023新闻摘抄十条_蚁百杭州网站seo优化

Failed to locate Teleport target with selector “.demon”. Note the target element must exist before the component is mounted - i.e. the target cannot be rendered by the component itself, and ideally should be outside of the entire Vue component tree
main.js:8 [Vue warn]: Invalid Teleport target on mount: null (object)

vue 项目引用 Teleport 的时候报错

注:写这篇的目的是以此为戒不再犯蠢 啊啊啊 这真是让我吐槽一天都不止的蠢问题

父组件
<template><div><div id="container">这是id:container</div><div class="demon">这是class:main</div><Demo> </Demo></div>
</template>
<script setup>
import Demo from "@/components/Demo.vue";
</script>
<style scoped></style>
子组件
<template><div><div>这是子组件</div><Teleport to="#container"><div>这是传送 Teleport的内容</div></Teleport></div>
</template>
<script setup></script>
<style scoped></style>

看着没啥问题 可是控制台就是报警告而且teleport 时管用时不管用
在这里插入图片描述

解决问题

原因是 vue文档中表示 teleport 需要 加上 defer 属性 无论刷新还是重新加载 传送组件就不会报错了

使用 defer prop 推迟 Teleport 的目标解析,直到应用的其他部分挂载。这允许 Teleport 将由 Vue 渲染且位于组件树之后部分的容器元素作为目标

在这里插入图片描述

唉 还是得细心看文档 一时粗心 耽误事儿啊。。。
在这里插入图片描述

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com