Nuxt/Vue: How to position custom loading component

泪湿孤枕 提交于 2020-01-05 06:45:02

问题


I use nuxt and I followed this guide to make custom loading component: https://nuxtjs.org/api/configuration-loading/#use-a-custom-loading-component

This does work, but the loader is in the same position as the original nuxt loader bar:

You can see, I really added a very big and very simple loader with a red div.

At the bottom you can see my headebar (black bar with letter «s») so everything is moved downwards.

What I would like to achieve is that the loader takes the position of the page content instead to keep the header and the footer in place. Right now, it all shifts down to make space for the custom loader on top.

Is there a solution for that? Thanks in advance

Cheers

J


回答1:


Well I built a big workaround:

I set a loading component in my nuxt.config:

loading: '~/components/Loading/Loading.vue',

This component should never display anything, but has these two methods:

methods: {
  start () {
    this.$store.commit('ui/SHOW_LOADER')
  },
  finish () {
    this.$store.commit('ui/HIDE_LOADER')
  }
}

With those I mutate the vuex ui store.

export const mutations = {
  SHOW_LOADER (state) {
    state.nuxtLoader = true
  },
  HIDE_LOADER (state) {
    state.nuxtLoader = false
  }
}

nuxtLoader: false, <=> nuxtLoader: true,

Within this store I set a getter:

export const getters = {
  nuxtLoader: state => state.nuxtLoader
}

And on my layouts I display <nuxt /> or the CustomLoader component (which holds an animated SVG) depending on the ui store nuxtLoader property.

<template>
    <div>
      <HeaderBar />
      <main id="main" class="Layout__content">
        <CustomLoader v-if="nuxtLoader" />
        <nuxt v-else />
      </main>
      <Footer />
    </div>
</template>

Now I give the user a feedback with a custom loader placed between headerbar and footer. 💪

I am still open for less work-aroundy and slicker solutions.

Cheers

J



来源:https://stackoverflow.com/questions/51279498/nuxt-vue-how-to-position-custom-loading-component

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!