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