chore: use data-fetch-key instead of data-ssr-key

This commit is contained in:
Sébastien Chopin 2020-02-12 16:41:23 +01:00
parent 539c865533
commit b71eaee879
2 changed files with 7 additions and 7 deletions

View File

@ -1,7 +1,7 @@
import Vue from 'vue'
import { hasFetch, normalizeError, addLifecycleHook } from '../utils'
const isSsrHydration = (vm) => vm.$vnode && vm.$vnode.elm && vm.$vnode.elm.dataset && vm.$vnode.elm.dataset.ssrKey
const isSsrHydration = (vm) => vm.$vnode && vm.$vnode.elm && vm.$vnode.elm.dataset && vm.$vnode.elm.dataset.fetchKey
const nuxtState = window.<%= globals.context %>
export default {
@ -37,8 +37,8 @@ function created() {
// Hydrate component
this._hydrated = true
this._ssrKey = +this.$vnode.elm.dataset.ssrKey
const data = nuxtState.fetch[this._ssrKey]
this._fetchKey = +this.$vnode.elm.dataset.fetchKey
const data = nuxtState.fetch[this._fetchKey]
// If fetch error
if (data && data._error) {

View File

@ -16,13 +16,13 @@ async function serverPrefetch() {
// Define an ssrKey for hydration
this._ssrKey = this.$ssrContext.nuxt.fetch.length
this._fetchKey = this.$ssrContext.nuxt.fetch.length
// Add data-ssr-key on parent element of Component
// Add data-fetch-key on parent element of Component
const attrs = this.$vnode.data.attrs = this.$vnode.data.attrs || {}
attrs['data-ssr-key'] = this._ssrKey
attrs['data-fetch-key'] = this._fetchKey
// Call asyncData & add to ssrContext for window.__NUXT__.fetch
// Add to ssrContext for window.__NUXT__.fetch
this.$ssrContext.nuxt.fetch.push(this.$fetchState.error ? { _error: this.$fetchState.error } : this._data)
}