From e848b9d0b0a1804388eb51d328ab6054d89aa979 Mon Sep 17 00:00:00 2001 From: erra Date: Wed, 27 May 2020 02:00:02 +0800 Subject: [PATCH] fix(plugin): always get global `$nuxt` while loading (#364) --- lib/plugin.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/plugin.js b/lib/plugin.js index a421b43c..47e08017 100644 --- a/lib/plugin.js +++ b/lib/plugin.js @@ -2,8 +2,6 @@ import Axios from 'axios' import defu from 'defu' <% if (options.retry) { %>import axiosRetry from 'axios-retry'<% } %> -const $nuxt = typeof window !== 'undefined' && window['$<%= options.globalName %>'] - // Axios.prototype cannot be modified const axiosExtra = { setBaseURL (baseURL) { @@ -128,7 +126,10 @@ const setupProgress = (axios) => { set: () => { } } - const $loading = () => ($nuxt && $nuxt.$loading && $nuxt.$loading.set) ? $nuxt.$loading : noopLoading + const $loading = () => { + const $nuxt = typeof window !== 'undefined' && window['$<%= options.globalName %>'] + return ($nuxt && $nuxt.$loading && $nuxt.$loading.set) ? $nuxt.$loading : noopLoading + } let currentRequests = 0