@@ -17,8 +17,17 @@ import {
17
17
globalHandleError
18
18
} from '. / utils . js '
19
19
import { createApp < % if ( features . layouts ) { % > , NuxtError < % } %> } from '. / index . js '
20
+ < % if ( features . fetch ) { % > import fetchMixin from './mixins/fetch.client'< % } % >
20
21
import NuxtLink from './components/nuxt-link.< %= features . clientPrefetch ? "client " : "server " % > .js' // should be included after ./index.js
21
22
23
+ < % if ( features . fetch ) { % >
24
+ // Fetch mixin
25
+ if (!Vue.__nuxt__fetch__mixin__) {
26
+ Vue . mixin ( fetchMixin )
27
+ Vue . __nuxt__fetch__mixin__ = true
28
+ }
29
+ < % } % >
30
+
22
31
// Component: < NuxtLink >
23
32
Vue.component(NuxtLink.name, NuxtLink)
24
33
< % if ( features . componentAliases ) { % > Vue.component('NLink', NuxtLink)< % } % >
@@ -458,7 +467,10 @@ async function render (to, from, next) {
458
467
< % } %>
459
468
460
469
< % if ( features . fetch ) { % >
461
- const hasFetch = Boolean(Component.options.fetch)
470
+ const hasFetch = Boolean(Component.options.fetch) && Component . options . fetch . length
471
+ if ( hasFetch ) {
472
+ console . warn ( 'fetch(context) has been deprecated, please use middleware(context)' )
473
+ }
462
474
< % } else { % >
463
475
const hasFetch = false
464
476
< % } %>
@@ -738,7 +750,7 @@ function addHotReload ($component, depth) {
738
750
< % if ( features . fetch ) { % >
739
751
// Call fetch()
740
752
Component . options . fetch = Component . options . fetch || noopFetch
741
- let pFetch = Component . options . fetch ( context )
753
+ let pFetch = Component . options . fetch . length && Component . options . fetch ( context )
742
754
if ( ! pFetch || ( ! ( pFetch instanceof Promise ) && ( typeof pFetch . then !== 'function' ) ) ) { pFetch = Promise . resolve ( pFetch ) }
743
755
< %= ( loading ? 'pFetch.then(() => this.$loading.increase && this.$loading.increase(30))' : '' ) % >
744
756
promises . push ( pFetch )
0 commit comments