mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-26 23:52:06 +00:00
fix(vue-app): static payload fetching bugfixes (#8701)
This commit is contained in:
parent
dc551f9709
commit
febd7ee43c
@ -324,22 +324,22 @@ export default {
|
|||||||
this._pagePayload = payload
|
this._pagePayload = payload
|
||||||
this._fetchCounters = {}
|
this._fetchCounters = {}
|
||||||
},
|
},
|
||||||
async fetchPayload(route) {
|
async fetchPayload(route, prefetch) {
|
||||||
<% if (nuxtOptions.generate.manifest) { %>
|
<% if (nuxtOptions.generate.manifest) { %>
|
||||||
const manifest = await this.fetchStaticManifest()
|
const manifest = await this.fetchStaticManifest()
|
||||||
const path = this.getRoutePath(route)
|
const path = this.getRoutePath(route)
|
||||||
if (!manifest.routes.includes(path)) {
|
if (!manifest.routes.includes(path)) {
|
||||||
this.setPagePayload(false)
|
if (!prefetch) { this.setPagePayload(false) }
|
||||||
throw new Error(`Route ${path} is not pre-rendered`)
|
throw new Error(`Route ${path} is not pre-rendered`)
|
||||||
}
|
}
|
||||||
<% } %>
|
<% } %>
|
||||||
const src = urlJoin(this.getStaticAssetsPath(route), 'payload.js')
|
const src = urlJoin(this.getStaticAssetsPath(route), 'payload.js')
|
||||||
try {
|
try {
|
||||||
const payload = await window.__NUXT_IMPORT__(decodeURI(route), encodeURI(src))
|
const payload = await window.__NUXT_IMPORT__(decodeURI(route), encodeURI(src))
|
||||||
this.setPagePayload(payload)
|
if (!prefetch) { this.setPagePayload(payload) }
|
||||||
return payload
|
return payload
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.setPagePayload(false)
|
if (!prefetch) { this.setPagePayload(false) }
|
||||||
throw err
|
throw err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,9 @@ import {
|
|||||||
import { createApp<% if (features.layouts) { %>, NuxtError<% } %> } from './index.js'
|
import { createApp<% if (features.layouts) { %>, NuxtError<% } %> } from './index.js'
|
||||||
<% if (features.fetch) { %>import fetchMixin from './mixins/fetch.client'<% } %>
|
<% if (features.fetch) { %>import fetchMixin from './mixins/fetch.client'<% } %>
|
||||||
import NuxtLink from './components/nuxt-link.<%= features.clientPrefetch ? "client" : "server" %>.js' // should be included after ./index.js
|
import NuxtLink from './components/nuxt-link.<%= features.clientPrefetch ? "client" : "server" %>.js' // should be included after ./index.js
|
||||||
<% if (isFullStatic) { %>import './jsonp'<% } %>
|
<% if (isFullStatic) { %>import { installJsonp } from './jsonp'<% } %>
|
||||||
|
|
||||||
|
<% if (isFullStatic) { %>installJsonp()<% } %>
|
||||||
|
|
||||||
<% if (features.fetch) { %>
|
<% if (features.fetch) { %>
|
||||||
// Fetch mixin
|
// Fetch mixin
|
||||||
|
@ -112,7 +112,7 @@ export default {
|
|||||||
if (!this.$root.isPreview) {
|
if (!this.$root.isPreview) {
|
||||||
const { href } = this.$router.resolve(this.to, this.$route, this.append)
|
const { href } = this.$router.resolve(this.to, this.$route, this.append)
|
||||||
if (this.<%= globals.nuxt %>)
|
if (this.<%= globals.nuxt %>)
|
||||||
this.<%= globals.nuxt %>.fetchPayload(href).catch(() => {})
|
this.<%= globals.nuxt %>.fetchPayload(href, true).catch(() => {})
|
||||||
}
|
}
|
||||||
<% } %>
|
<% } %>
|
||||||
<% if (router.linkPrefetchedClass) { %>
|
<% if (router.linkPrefetchedClass) { %>
|
||||||
|
@ -75,6 +75,9 @@ function importChunk(chunkId, src) {
|
|||||||
return promise
|
return promise
|
||||||
}
|
}
|
||||||
|
|
||||||
window.__NUXT_JSONP__ = function (chunkId, exports) { chunks[chunkId] = exports }
|
export function installJsonp() {
|
||||||
window.__NUXT_JSONP_CACHE__ = chunks
|
window.__NUXT_JSONP__ = function (chunkId, exports) { chunks[chunkId] = exports }
|
||||||
window.__NUXT_IMPORT__ = importChunk
|
window.__NUXT_JSONP_CACHE__ = chunks
|
||||||
|
window.__NUXT_IMPORT__ = importChunk
|
||||||
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user