UNPKG

2.17 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6
7var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
8
9var _axios = require('axios');
10
11var _axios2 = _interopRequireDefault(_axios);
12
13function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14
15/**
16 * Copied from vue-resource
17 */
18
19var slice = [].slice;
20
21
22function isFunction(val) {
23 return typeof val === 'function';
24}
25
26var isArray = Array.isArray;
27
28function isPlainObject(obj) {
29 return isObject(obj) && Object.getPrototypeOf(obj) == Object.prototype;
30}
31
32function isObject(obj) {
33 return obj !== null && (typeof obj === 'undefined' ? 'undefined' : _typeof(obj)) === 'object';
34}
35
36function _merge(target, source, deep) {
37 for (var key in source) {
38 if (deep && (isPlainObject(source[key]) || isArray(source[key]))) {
39 if (isPlainObject(source[key]) && !isPlainObject(target[key])) {
40 target[key] = {};
41 }
42 if (isArray(source[key]) && !isArray(target[key])) {
43 target[key] = [];
44 }
45 _merge(target[key], source[key], deep);
46 } else if (source[key] !== undefined) {
47 target[key] = source[key];
48 }
49 }
50}
51
52function merge(target) {
53
54 var args = slice.call(arguments, 1);
55
56 args.forEach(function (source) {
57 _merge(target, source, true);
58 });
59
60 return target;
61}
62
63function options(fn, obj, opts) {
64
65 opts = opts || {};
66
67 if (isFunction(opts)) {
68 opts = opts.call(obj);
69 }
70
71 return merge(fn.bind({ $vm: obj, $options: opts }), fn, { $options: opts });
72}
73
74/**
75 * Install plugin
76 * @param Vue
77 */
78
79function plugin(Vue) {
80
81 if (plugin.installed) {
82 return;
83 }
84
85 Vue.axios = _axios2.default;
86
87 Object.defineProperties(Vue.prototype, {
88
89 axios: {
90 get: function get() {
91 return options(Vue.axios, this, this.$options.axios);
92 }
93 }
94
95 });
96}
97
98if (typeof window !== 'undefined' && window.Vue) {
99 window.Vue.use(plugin);
100}
101
102exports.default = plugin;
\No newline at end of file