Skip to content

Commit 87a157a

Browse files
committed
Backward support vue version < 3.0.0
1 parent 15eba13 commit 87a157a

File tree

3 files changed

+84
-85
lines changed

3 files changed

+84
-85
lines changed

package-lock.json

Lines changed: 55 additions & 80 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
"homepage": "https://github.com/imcvampire/vue-axios#readme",
3131
"dependencies": {
3232
"axios": "^0.20.0",
33-
"vue": "^3.0.0"
33+
"semver": "^7.3.2",
34+
"vue": "^2.0.0"
3435
},
3536
"devDependencies": {
3637
"@babel/core": "^7.11.6",

src/index.js

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
(function () {
2-
2+
const semver = require('semver')
33
/**
44
* Install plugin
55
* @param app
@@ -16,12 +16,35 @@ function plugin(app, axios) {
1616
return
1717
}
1818

19+
if (!!!semver.valid(app.version)) {
20+
console.error('Unkown vue version')
21+
return
22+
}
23+
1924
plugin.installed = true;
2025

21-
app.axios = axios;
26+
if (semver.lt(app.version, '3.0.0')) {
27+
Object.defineProperties(app.prototype, {
2228

23-
app.config.globalProperties.axios = axios;
24-
app.config.globalProperties.$http = axios;
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;
2548
}
2649

2750
if (typeof exports == "object") {

0 commit comments

Comments
 (0)