Skip to content

Commit 4bb1e96

Browse files
committed
feat: Ver 1.0.0
1 parent b281031 commit 4bb1e96

File tree

5 files changed

+125
-0
lines changed

5 files changed

+125
-0
lines changed

dist/vue-axios.es5.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
'use strict';
2+
3+
Object.defineProperty(exports, "__esModule", {
4+
value: true
5+
});
6+
7+
var _axios = require('axios');
8+
9+
var _axios2 = _interopRequireDefault(_axios);
10+
11+
var _utils = require('./utils');
12+
13+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14+
15+
function plugin(Vue) {
16+
17+
if (plugin.installed) {
18+
return;
19+
}
20+
21+
Vue.axios = _axios2.default;
22+
23+
Object.defineProperties(Vue.prototype, {
24+
25+
axios: {
26+
get: function get() {
27+
return (0, _utils.options)(Vue.axios, this, this.$options.axios);
28+
}
29+
}
30+
31+
});
32+
}
33+
34+
if (typeof window !== 'undefined' && window.Vue) {
35+
window.Vue.use(plugin);
36+
}
37+
38+
exports.default = plugin;

dist/vue-axios.min.js

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

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,15 @@
2222
},
2323
"homepage": "https://github.com/imcvampire/vue-axios#readme",
2424
"devDependencies": {
25+
"vue": "^2.0.3",
2526
"babel-core": "^6.18.0",
2627
"babel-preset-es2015": "^6.18.0",
2728
"gulp": "^3.9.1",
2829
"gulp-babel": "^6.1.2",
2930
"gulp-rename": "^1.2.2",
3031
"gulp-uglifyjs": "^0.6.2"
32+
},
33+
"dependencies": {
34+
"axios": "^0.15.2"
3135
}
3236
}

src/index.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import axios from 'axios';
2+
import { options } from './utils'
3+
4+
function plugin(Vue) {
5+
6+
if (plugin.installed) {
7+
return;
8+
}
9+
10+
Vue.axios = axios
11+
12+
Object.defineProperties(Vue.prototype, {
13+
14+
axios: {
15+
get() {
16+
return options(Vue.axios, this, this.$options.axios);
17+
}
18+
},
19+
20+
});
21+
}
22+
23+
if (typeof window !== 'undefined' && window.Vue) {
24+
window.Vue.use(plugin);
25+
}
26+
27+
export default plugin;

src/utils.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/**
2+
* Copied from vue-resource
3+
*/
4+
5+
function isFunction(val) {
6+
return typeof val === 'function';
7+
}
8+
9+
const isArray = Array.isArray;
10+
11+
function isPlainObject(obj) {
12+
return isObject(obj) && Object.getPrototypeOf(obj) == Object.prototype;
13+
}
14+
15+
function isObject(obj) {
16+
return obj !== null && typeof obj === 'object';
17+
}
18+
19+
function _merge(target, source, deep) {
20+
for (var key in source) {
21+
if (deep && (isPlainObject(source[key]) || isArray(source[key]))) {
22+
if (isPlainObject(source[key]) && !isPlainObject(target[key])) {
23+
target[key] = {};
24+
}
25+
if (isArray(source[key]) && !isArray(target[key])) {
26+
target[key] = [];
27+
}
28+
_merge(target[key], source[key], deep);
29+
} else if (source[key] !== undefined) {
30+
target[key] = source[key];
31+
}
32+
}
33+
}
34+
35+
function merge(target) {
36+
37+
var args = slice.call(arguments, 1);
38+
39+
args.forEach((source) => {
40+
_merge(target, source, true);
41+
});
42+
43+
return target;
44+
}
45+
46+
export function options(fn, obj, opts) {
47+
48+
opts = opts || {};
49+
50+
if (isFunction(opts)) {
51+
opts = opts.call(obj);
52+
}
53+
54+
return merge(fn.bind({$vm: obj, $options: opts}), fn, {$options: opts});
55+
}

0 commit comments

Comments
 (0)