Skip to content

Commit 12da6c8

Browse files
author
pooya parsa
committed
fix: globalName fallback for nuxt < 2.2.0
1 parent b0483da commit 12da6c8

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

lib/module.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ function axiosModule (_moduleOptions) {
9494
options.browserBaseURL = https(options.browserBaseURL)
9595
}
9696

97+
// globalName
98+
options.globalName = this.nuxt.options.globalName || 'nuxt'
99+
97100
// Register plugin
98101
this.addPlugin({
99102
src: path.resolve(__dirname, 'plugin.js'),

lib/plugin.js

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

5-
const globalName = '$<%= globalName %>'
5+
const $nuxt = typeof window !== 'undefined' && window['$<%= options.globalName %>']
66

77
// Axios.prototype cannot be modified
88
const axiosExtra = {
@@ -128,7 +128,7 @@ const setupProgress = (axios) => {
128128
set: () => { }
129129
}
130130

131-
const $loading = () => (window[globalName] && window[globalName].$loading && window[globalName].$loading.set) ? window[globalName].$loading : noopLoading
131+
const $loading = () => ($nuxt && $nuxt.$loading && $nuxt.$loading.set) ? $nuxt.$loading : noopLoading
132132

133133
let currentRequests = 0
134134

0 commit comments

Comments
 (0)