Skip to content
Permalink
Browse files
fix: globalName fallback for nuxt < 2.2.0
  • Loading branch information
pooya parsa committed Apr 30, 2020
1 parent b0483da commit 12da6c8e2feb8cf4f7e918fbbe4693400152c1ff
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
@@ -94,6 +94,9 @@ function axiosModule (_moduleOptions) {
options.browserBaseURL = https(options.browserBaseURL)
}

// globalName
options.globalName = this.nuxt.options.globalName || 'nuxt'

// Register plugin
this.addPlugin({
src: path.resolve(__dirname, 'plugin.js'),
@@ -2,7 +2,7 @@ import Axios from 'axios'
import defu from 'defu'
<% if (options.retry) { %>import axiosRetry from 'axios-retry'<% } %>

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

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

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

let currentRequests = 0

0 comments on commit 12da6c8

Please sign in to comment.