yoho-plugin-core.js
1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/**
* 插件
*/
import iView from 'iview';
import Router from 'vue-router';
import store from 'yoho-store';
import cookie from 'yoho-cookie';
import components from '../components/global';
import axios from 'axios';
import config from 'config';
import _ from 'lodash';
const plugin = {
install(Vue, options) {
// 加载核心插件
Vue.use(iView);
Vue.use(Router);
Vue.prop = (key, value) => {
Vue[`$${key}`] = Vue.prototype[`$${key}`] = value;
};
// 附加Vue原型属性
if (config) {
Vue.prop('config', config);
}
if (options && options.router) {
Vue.$router = options.router;
}
Vue.prop('store', store);
Vue.prop('cookie', cookie);
// 加载核心组件
_.each(components, component => {
Vue.component(component.name, component);
});
Vue.beforeRender = [];
Vue.render = opts => {
return new Promise(resolve => {
if (Vue.beforeRender.length) {
let step = index => {
if (index >= Vue.beforeRender.length) {
resolve();
} else {
Vue.beforeRender[index](() => {
step(index + 1);
});
}
};
step(0);
} else {
resolve();
}
}).then(() => {
return new Vue(opts);
});
};
// 设置axios默认参数
axios.defaults.baseURL = '/Api';
axios.defaults.responseType = 'json';
}
};
export default plugin;