Skip to content

Commit e848b9d

Browse files
authored
fix(plugin): always get global $nuxt while loading (#364)
1 parent 0957082 commit e848b9d

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

lib/plugin.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ import Axios from 'axios'
22
import defu from 'defu'
33
<% if (options.retry) { %>import axiosRetry from 'axios-retry'<% } %>
44

5-
const $nuxt = typeof window !== 'undefined' && window['$<%= options.globalName %>']
6-
75
// Axios.prototype cannot be modified
86
const axiosExtra = {
97
setBaseURL (baseURL) {
@@ -128,7 +126,10 @@ const setupProgress = (axios) => {
128126
set: () => { }
129127
}
130128

131-
const $loading = () => ($nuxt && $nuxt.$loading && $nuxt.$loading.set) ? $nuxt.$loading : noopLoading
129+
const $loading = () => {
130+
const $nuxt = typeof window !== 'undefined' && window['$<%= options.globalName %>']
131+
return ($nuxt && $nuxt.$loading && $nuxt.$loading.set) ? $nuxt.$loading : noopLoading
132+
}
132133

133134
let currentRequests = 0
134135

0 commit comments

Comments
 (0)