Skip to content

Commit

Permalink
fix: globalName fallback for nuxt < 2.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
pooya parsa committed Apr 30, 2020
1 parent b0483da commit 12da6c8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 3 additions & 0 deletions lib/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down
4 changes: 2 additions & 2 deletions lib/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 12da6c8

Please sign in to comment.