Skip to content

Commit

Permalink
feat: fix axios global import
Browse files Browse the repository at this point in the history
  • Loading branch information
pikax committed Nov 1, 2019
1 parent 8021456 commit 993973a
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 23 deletions.
8 changes: 4 additions & 4 deletions dist/vue-composable.cjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }

var compositionApi = require('@vue/composition-api');
var _axios = _interopDefault(require('axios'));
var axios = _interopDefault(require('axios'));

// export function unwrap<T>(o: RefTyped<T>): T {
// return isRef(o) ? o.value : o;
Expand Down Expand Up @@ -320,11 +320,11 @@ function useFetch(options) {
}

/* istanbul ignore next */
const axios = _axios || (globalThis && globalThis.axios);
const _axios = axios || (globalThis && globalThis.axios);
function useAxios(config) {
/* istanbul ignore next */
process.env.NODE_ENV !== "production" && !axios && console.warn(`[axios] not installed, please install it`);
const axiosClient = axios.create(config);
process.env.NODE_ENV !== "production" && !_axios && console.warn(`[axios] not installed, please install it`);
const axiosClient = _axios.create(config);
const client = compositionApi.computed(() => axiosClient);
const use = usePromise(async (request) => {
return axiosClient.request(request);
Expand Down
8 changes: 4 additions & 4 deletions dist/vue-composable.es.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { isRef, ref, onMounted, onUnmounted, computed, watch } from '@vue/composition-api';
import _axios from 'axios';
import axios from 'axios';

// export function unwrap<T>(o: RefTyped<T>): T {
// return isRef(o) ? o.value : o;
Expand Down Expand Up @@ -314,11 +314,11 @@ function useFetch(options) {
}

/* istanbul ignore next */
const axios = _axios || (globalThis && globalThis.axios);
const _axios = axios || (globalThis && globalThis.axios);
function useAxios(config) {
/* istanbul ignore next */
process.env.NODE_ENV !== "production" && !axios && console.warn(`[axios] not installed, please install it`);
const axiosClient = axios.create(config);
process.env.NODE_ENV !== "production" && !_axios && console.warn(`[axios] not installed, please install it`);
const axiosClient = _axios.create(config);
const client = computed(() => axiosClient);
const use = usePromise(async (request) => {
return axiosClient.request(request);
Expand Down
12 changes: 6 additions & 6 deletions dist/vue-composable.umd.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@vue/composition-api'), require('axios')) :
typeof define === 'function' && define.amd ? define(['exports', '@vue/composition-api', 'axios'], factory) :
(global = global || self, factory(global.vueComposable = {}, global.vueCompositionApi, global._axios));
}(this, (function (exports, compositionApi, _axios) { 'use strict';
(global = global || self, factory(global.vueComposable = {}, global.vueCompositionApi, global.axios));
}(this, (function (exports, compositionApi, axios) { 'use strict';

_axios = _axios && _axios.hasOwnProperty('default') ? _axios['default'] : _axios;
axios = axios && axios.hasOwnProperty('default') ? axios['default'] : axios;

// export function unwrap<T>(o: RefTyped<T>): T {
// return isRef(o) ? o.value : o;
Expand Down Expand Up @@ -319,11 +319,11 @@
}

/* istanbul ignore next */
const axios = _axios || (globalThis && globalThis.axios);
const _axios = axios || (globalThis && globalThis.axios);
function useAxios(config) {
/* istanbul ignore next */
!axios && console.warn(`[axios] not installed, please install it`);
const axiosClient = axios.create(config);
!_axios && console.warn(`[axios] not installed, please install it`);
const axiosClient = _axios.create(config);
const client = compositionApi.computed(() => axiosClient);
const use = usePromise(async (request) => {
return axiosClient.request(request);
Expand Down
10 changes: 5 additions & 5 deletions dist/vue-composable.umd.prod.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@vue/composition-api'), require('axios')) :
typeof define === 'function' && define.amd ? define(['exports', '@vue/composition-api', 'axios'], factory) :
(global = global || self, factory(global.vueComposable = {}, global.vueCompositionApi, global._axios));
}(this, (function (exports, compositionApi, _axios) { 'use strict';
(global = global || self, factory(global.vueComposable = {}, global.vueCompositionApi, global.axios));
}(this, (function (exports, compositionApi, axios) { 'use strict';

_axios = _axios && _axios.hasOwnProperty('default') ? _axios['default'] : _axios;
axios = axios && axios.hasOwnProperty('default') ? axios['default'] : axios;

// export function unwrap<T>(o: RefTyped<T>): T {
// return isRef(o) ? o.value : o;
Expand Down Expand Up @@ -307,9 +307,9 @@
}

/* istanbul ignore next */
const axios = _axios || (globalThis && globalThis.axios);
const _axios = axios || (globalThis && globalThis.axios);
function useAxios(config) {
const axiosClient = axios.create(config);
const axiosClient = _axios.create(config);
const client = compositionApi.computed(() => axiosClient);
const use = usePromise(async (request) => {
return axiosClient.request(request);
Expand Down
8 changes: 4 additions & 4 deletions src/web/axios.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { ref, computed, watch } from "@vue/composition-api";
import _axios, { AxiosRequestConfig, AxiosError } from "axios";
import axios, { AxiosRequestConfig, AxiosError } from "axios";
import { usePromise } from "../promise/promise";

/* istanbul ignore next */
const axios = _axios || (globalThis && (globalThis as any).axios);
const _axios = axios || (globalThis && (globalThis as any).axios);

export function useAxios<TData = any>(config?: AxiosRequestConfig) {
/* istanbul ignore next */
__DEV__ && !axios && console.warn(`[axios] not installed, please install it`);
__DEV__ && !_axios && console.warn(`[axios] not installed, please install it`);

const axiosClient = axios.create(config);
const axiosClient = _axios.create(config);
const client = computed(() => axiosClient);
const use = usePromise(async (request: AxiosRequestConfig) => {
return axiosClient.request(request);
Expand Down

0 comments on commit 993973a

Please sign in to comment.