UNPKG

1.05 kBJavaScriptView Raw
1import semver from 'semver';
2
3(function () {
4/**
5 * Install plugin
6 * @param app
7 * @param axios
8 */
9
10function plugin(app, axios) {
11 if (plugin.installed) {
12 return;
13 }
14
15 if (!axios) {
16 console.error('You have to install axios');
17 return;
18 }
19
20 if (semver.valid(app.version) == null) {
21 console.error('Unkown vue version');
22 return;
23 }
24
25 plugin.installed = true;
26
27 if (semver.lt(app.version, '3.0.0')) {
28 Object.defineProperties(app.prototype, {
29
30 axios: {
31 get: function get() {
32 return axios;
33 }
34 },
35
36 $http: {
37 get: function get() {
38 return axios;
39 }
40 }
41
42 });
43 } else {
44 app.config.globalProperties.axios = axios;
45 app.config.globalProperties.$http = axios;
46 }
47
48 app.axios = axios;
49 app.$http = axios;
50}
51
52if (typeof exports == "object") {
53 module.exports = plugin;
54} else if (typeof define == "function" && define.amd) {
55 define([], function(){ return plugin });
56} else if (window.Vue && window.axios) {
57 Vue.use(plugin, window.axios);
58}
59})();