yoho-plugin-core.js
1.12 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
/**
* 插件
*/
import iView from 'iview';
import Router from 'vue-router';
import store from 'yoho-store';
import components from '../components/common';
import axios from 'axios';
import config from 'config';
import _ from 'lodash';
const plugin = {
install(Vue, options) {
// 加载核心插件
Vue.use(iView);
Vue.use(Router);
// 附加Vue原型属性
if (config) {
Vue.prototype.$config = config;
}
if (options && options.router) {
Vue.$router = options.router;
options.router.beforeEach((to, from, next) => {
if (to.matched.length === 0) {
return next('/404.html');
}
return next();
});
}
Vue.$store = store;
Vue.prototype.$store = store;
// 加载核心组件
_.each(components, component => {
Vue.component(component.name, component);
});
// 设置axios默认参数
axios.defaults.baseURL = '/Api';
axios.defaults.responseType = 'json';
}
};
export default plugin;