UNPKG

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