nuxt3之NuxtPage中key的使用:
For example, passing static key, NuxtPage component is rendered only once when it is mounted.
<template>
<NuxtLayout
name="event-subpage"
:can-display-sidebar
>
<NuxtPage page-key="static" />
</NuxtLayout>
</template>
<NuxtPage>: 这是Nuxt.js中用于渲染当前路由页面内容的组件。
page-key="static": 这个属性用于强制组件重新渲染。设置为"static"意味着 <NuxtPage> 组件实例保持不变,但它内部的路由匹配逻辑仍然正常工作,允许子页面根据路由变化而更新。
当在 parent.vue 中使用 <NuxtPage page-key="static" /> 时,整个 parent.vue 组件应该也不会重新渲染。
这包括 parent.vue 中的所有静态内容和 <NuxtPage> 组件本身。
参考: https://nuxt.com/docs/api/components/nuxt-page
