UNPKG

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