NUXT3 NuxtLoadingIndicator切换布局卡住的解决

不得不说官方文档就是个坑
这是官方用法,在切换布局时,加载进度条会卡住

<template>
  <NuxtLayout>
    <div>
      <NuxtLoadingIndicator /> <!-- 在这里 -->
      <NuxtPage />
    </div>
  </NuxtLayout>
</template>

解决办法就是移出来

<template>
  <NuxtLoadingIndicator :throttle="0"  />
  <NuxtLayout>
    <NuxtPage />
  </NuxtLayout>
</template>
Nuxt 3中,页面与布局之间可以通过多种方式进行参数传递。以下是几种常见的方法: ### 1. 使用`useState`进行状态管理 Nuxt 3引入了`useState`,它可以在组件之间共享状态。你可以在布局组件中定义一个状态,然后在页面组件中修改这个状态。 **布局组件(layouts/default.vue):** ```vue <template> <div> <header>{{ title }}</header> <slot /> </div> </template> <script setup> import { useState } from &#39;#app&#39;; const title = useState(&#39;title&#39;, () => &#39;默认标题&#39;); </script> ``` **页面组件(pages/index.vue):** ```vue <script setup> import { useState } from &#39;#app&#39;; const setTitle = useState(&#39;title&#39;); setTitle.value = &#39;页面标题&#39;; </script> <template> <div> <h1>这是首页</h1> </div> </template> ``` ### 2. 使用`provide`和`inject` `provide`和`inject`是Vue 3提供的一种依赖注入方式,可以在组件树中传递数据。 **布局组件(layouts/default.vue):** ```vue <template> <div> <header>{{ title }}</header> <slot /> </div> </template> <script setup> import { provide } from &#39;vue&#39;; const title = ref(&#39;默认标题&#39;); provide(&#39;title&#39;, title); </script> ``` **页面组件(pages/index.vue):** ```vue <script setup> import { inject } from &#39;vue&#39;; const title = inject(&#39;title&#39;); title.value = &#39;页面标题&#39;; </script> <template> <div> <h1>这是首页</h1> </div> </template> ``` ### 3. 使用`props` 你可以在布局组件中定义`props`,然后在页面组件中传递这些`props`。 **布局组件(layouts/default.vue):** ```vue <template> <div> <header>{{ title }}</header> <slot /> </div> </template> <script setup> const props = defineProps({ title: { type: String, default: &#39;默认标题&#39; } }); </script> ``` **页面组件(pages/index.vue):** ```vue <script setup> import { ref } from &#39;vue&#39;; const title = ref(&#39;页面标题&#39;); </script> <template> <DefaultLayout :title="title"> <h1>这是首页</h1> </DefaultLayout> </template> ``` ### 4. 使用Vuex或Pinia进行全局状态管理 如果你的应用比较复杂,可以使用Vuex或Pinia进行全局状态管理。 **Vuex示例:** ```javascript // store/index.js export const state = () => ({ title: &#39;默认标题&#39; }); export const mutations = { setTitle(state, title) { state.title = title; } }; ``` **布局组件(layouts/default.vue):** ```vue <template> <div> <header>{{ title }}</header> <slot /> </div> </template> <script setup> import { mapState, mapMutations } from &#39;vuex&#39;; const { title } = mapState([&#39;title&#39;]); const { setTitle } = mapMutations([&#39;setTitle&#39;]); </script> ``` **页面组件(pages/index.vue):** ```vue <script setup> import { mapMutations } from &#39;vuex&#39;; const { setTitle } = mapMutations([&#39;setTitle&#39;]); setTitle(&#39;页面标题&#39;); </script> <template> <div> <h1>这是首页</h1> </div> </template> ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值