Skip to content

Commit 19a69bf

Browse files
author
sifan
committed
📦 插件升级为vue3
1 parent 78d2c6e commit 19a69bf

File tree

7 files changed

+53
-3434
lines changed

7 files changed

+53
-3434
lines changed

Gulpfile.js

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,28 @@
1-
const gulp = require('gulp');
1+
2+
const { src, dest, series } = require('gulp');
23
const babel = require('gulp-babel');
34
const uglify = require('gulp-uglifyjs');
45
const rename = require('gulp-rename');
6+
const clean = require('gulp-clean');
57

6-
gulp.task('default', () => {
7-
return gulp.src('src/index.js')
8+
function build() {
9+
return src('src/index.js', { allowEmpty: true })
810
.pipe(babel({
9-
presets: ['es2015']
11+
presets: [
12+
'@babel/env'
13+
]
1014
}))
1115
.pipe(rename('vue-axios.es5.js'))
12-
.pipe(gulp.dest('dist'))
16+
.pipe(dest('dist'))
1317
.pipe(uglify())
1418
.pipe(rename('vue-axios.min.js'))
15-
.pipe(gulp.dest('dist'));
16-
});
19+
.pipe(dest('dist'));
20+
}
21+
22+
function clear() {
23+
return src('dist/*').pipe(clean({
24+
force: true
25+
}));
26+
}
27+
28+
exports.default = series(clear, build)

dist/vue-axios.es5.js

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,27 @@
11
"use strict";
22

3-
var _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; };
3+
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
44

55
(function () {
6-
76
/**
87
* Install plugin
9-
* @param Vue
8+
* @param app
109
* @param axios
1110
*/
12-
13-
function plugin(Vue, axios) {
14-
11+
function plugin(app, axios) {
1512
if (plugin.installed) {
1613
return;
1714
}
18-
plugin.installed = true;
1915

2016
if (!axios) {
2117
console.error('You have to install axios');
2218
return;
2319
}
2420

25-
Vue.axios = axios;
26-
27-
Object.defineProperties(Vue.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-
});
21+
plugin.installed = true;
22+
app.axios = axios;
23+
app.config.globalProperties.axios = axios;
24+
app.config.globalProperties.$http = axios;
4225
}
4326

4427
if ((typeof exports === "undefined" ? "undefined" : _typeof(exports)) == "object") {

dist/vue-axios.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.d.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
1-
import Vue, {PluginFunction, PluginObject} from "vue";
21
import { AxiosStatic } from "axios";
2+
import { App } from "vue";
33

4-
declare module "vue/types/vue" {
5-
6-
interface Vue {
7-
axios: AxiosStatic;
4+
export declare function VAxios(app: App): AxiosStatic;
5+
declare module "@vue/runtime-core" {
6+
export interface ComponentCustomProperties {
87
$http: AxiosStatic;
8+
axios: AxiosStatic;
99
}
1010

11-
interface VueConstructor {
11+
export interface App {
1212
axios: AxiosStatic;
1313
}
1414
}
1515

16-
declare class VueAxios {
17-
static install: PluginFunction<AxiosStatic>;
18-
}
16+
declare function VueAxios(app: App, axios: AxiosStatic): void;
1917

2018
export default VueAxios;

0 commit comments

Comments
 (0)