Fix progress bar on different layouts (#113)

This commit is contained in:
Sébastien Chopin 2017-01-30 11:20:20 +01:00
parent 55003631fc
commit f33afa521f
3 changed files with 16 additions and 8 deletions

View File

@ -1,10 +1,13 @@
<template> <template>
<div id="__nuxt"> <div id="__nuxt">
<% if (loading) { %><nuxt-loading ref="loading"></nuxt-loading><% } %>
<component v-if="layout" :is="layout"></component> <component v-if="layout" :is="layout"></component>
</div> </div>
</template> </template>
<script> <script>
<% if (loading) { %>import NuxtLoading from '<%= (typeof loading === "string" ? loading : "./components/nuxt-loading.vue") %>'<% } %>
let layouts = { let layouts = {
<% <%
var layoutsKeys = Object.keys(layouts); var layoutsKeys = Object.keys(layouts);
@ -19,6 +22,12 @@ export default {
layout: null, layout: null,
layoutName: '' layoutName: ''
}), }),
<% if (loading) { %>
mounted () {
this.$loading = this.$refs.loading
this.$nuxt.$loading = this.$loading
},
<% } %>
methods: { methods: {
setLayout (layout) { setLayout (layout) {
if (!layout || !layouts['_' + layout]) layout = 'default' if (!layout || !layouts['_' + layout]) layout = 'default'
@ -44,6 +53,9 @@ export default {
console.error(e) console.error(e)
}) })
} }
},
components: {
<%= (loading ? 'NuxtLoading' : '') %>
} }
} }
</script> </script>

View File

@ -320,10 +320,6 @@ Promise.all(resolveComponents)
.then(({ _app, Components }) => { .then(({ _app, Components }) => {
const mountApp = () => { const mountApp = () => {
_app.$mount('#__nuxt') _app.$mount('#__nuxt')
<% if (loading) { %>
// Special loading bar
_app.$loading = _app.$nuxt.$loading
<% } %>
// Hot reloading // Hot reloading
hotReloadAPI(_app) hotReloadAPI(_app)
// Call window.onNuxtReady callbacks // Call window.onNuxtReady callbacks

View File

@ -1,6 +1,5 @@
<template> <template>
<div> <div>
<% if (loading) { %><nuxt-loading ref="loading"></nuxt-loading><% } %>
<nuxt-child v-if="!nuxt.err"></nuxt-child> <nuxt-child v-if="!nuxt.err"></nuxt-child>
<nuxt-error v-if="nuxt.err" :error="nuxt.err"></nuxt-error> <nuxt-error v-if="nuxt.err" :error="nuxt.err"></nuxt-error>
</div> </div>
@ -10,7 +9,6 @@
import Vue from 'vue' import Vue from 'vue'
import NuxtChild from './nuxt-child' import NuxtChild from './nuxt-child'
import NuxtError from '<%= components.ErrorPage %>' import NuxtError from '<%= components.ErrorPage %>'
<% if (loading) { %>import NuxtLoading from '<%= (typeof loading === "string" ? loading : "./nuxt-loading.vue") %>'<% } %>
export default { export default {
name: 'nuxt', name: 'nuxt',
@ -33,7 +31,9 @@ export default {
}, },
<% if (loading) { %> <% if (loading) { %>
mounted () { mounted () {
this.$loading = this.$refs.loading if (this.$root.$loading && this.$root.$loading.start) {
this.$loading = this.$root.$loading
}
}, },
watch: { watch: {
'nuxt.err': 'errorChanged' 'nuxt.err': 'errorChanged'
@ -49,7 +49,7 @@ export default {
<% } %> <% } %>
components: { components: {
NuxtChild, NuxtChild,
NuxtError<%= (loading ? ',\n NuxtLoading' : '') %> NuxtError
} }
} }
</script> </script>