core.js 954 Bytes
/**
 * 插件
 */
import store from 'yoho-store';
import cookie from 'yoho-cookie';
import iView from 'iview';
import 'iview/dist/styles/iview.css';
import components from '../components';
import _ from 'lodash/core';

export default {
    loadGlobalComponents(Vue) {
        _.each(components, component => {
            if (component.length) {
                Vue.component(component[0], component[1]);
            } else {
                Vue.component(component.name, component);
            }
        });
    },
    defineVueProp(Vue) {
        Vue.prop = (key, value) => {
            Vue[`$${key}`] = Vue.prototype[`$${key}`] = value;
        };
    },
    install(Vue) {
        // 定义Vue全局属性
        this.defineVueProp(Vue);

        // 加载核心组件
        this.loadGlobalComponents(Vue);

        // 附加Vue原型属性
        Vue.prop('store', store);
        Vue.prop('cookie', cookie);

        Vue.use(iView);
    }
};