Vue received a Component that was made a reactive object. This can lead to unnecessary performance o

vue3 +ts 项目 写路由菜单的时候菜单的子菜单显示不出来并且控制台报警告

以下为控制台报的警告
vue3+vite+ts 报错
Vue received a Component that was made a reactive object. This can
lead to unnecessary performance overhead and should be avoided by
marking the component with markRaw or using shallowRef instead of
ref. Component that was made reactive:

在这里插入图片描述
在这里插入图片描述

这是 错误示范的代码

<template>
	<template v-for="item in navMenus">
		<el-menu-item
			v-if="!(item.children && item.children.length > 0)"
			:key="item.path"
			:index="item.path"
		>
			<template #title>
				<component :is="item.icon" class="icons"></component>
				<span>{{ item.label }}</span>
			</template>
		</el-menu-item>
		<el-sub-menu v-else :index="item.path" id="item.path">
			<template #title>
				<component :is="item.icon" class="icons"></component>
				<span>{{ item.label }}</span>
			</template>
			<navMenus :navMenus="item.children"></navMenus>
		</el-sub-menu>
	</template>
</template>

<script setup>
defineProps(["navMenus"]);
</script>
<script>
export default {
	name: "navMenus",
};
</script>
<style scoped>
.icons {
	width: 18px;
	margin-right: 10px;
}
</style>

解决方法 : 给此组件另取的名字和 defineProps 传递的 navMenus 的名字冲突了 改个名字就好了

<template>
	<template v-for="item in navMenus">
		<el-menu-item
			v-if="!(item.children && item.children.length > 0)"
			:key="item.path"
			:index="item.path"
		>
			<template #title>
				<component :is="item.icon" class="icons"></component>
				<span>{{ item.label }}</span>
			</template>
		</el-menu-item>
		<el-sub-menu v-else :index="item.path" id="item.path">
			<template #title>
				<component :is="item.icon" class="icons"></component>
				<span>{{ item.label }}</span>
			</template>
			<navMenusItems :navMenus="item.children"></navMenusItems>
		</el-sub-menu>
	</template>
</template>

<script setup>
defineProps(["navMenus"]);
</script>
<script>
export default {
	name: "navMenusItems",
};
</script>
<style scoped>
.icons {
	width: 18px;
	margin-right: 10px;
}
</style>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值