yoho-plugin-core.js 1.12 KB
/**
 * 插件
 */
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;