(最近给自己立个小flag,看源码,每周至少看一篇源码)先说说两者基于Vue的源码基本结构UI框架,iview和ElemetUI以及区别。1.文件结构开发主要放在根文件夹下src下:1.ivew文件结构|--src|--components//所有UI组件|--directives|--locale//language|--mixins|--styles...index.less//样式文件|--utilsindex.js//入口文件元素UI文件结构:与iview略有不同之处●将componentsUI组件文件夹直接放在根文件夹下用于packages;●样式文件放在packages下的theme-chalk下,所有样式都导入到index.scss中;2、入口文件index.js和两个UI库基本相同,主要分为以下几步:1.引入所有UI组件:importPaginationfrom'../packages/pagination/index.js';importDialogfrom'../packages/dialog/index.js';...constcomponents=[Pagination,Dialog,...}2.installmethodconstinstall=function(Vue,opts={}){..}3。自动安装if(typeofwindow!=='undefined'&&window.Vue){install(window.Vue);}4.导出组件和其他需要导出的属性或方法module.exports={};//等价toES6exportdefault{};//想了解更多关于模块加载的可以去阮老师的文章//http://es6.ruanyifeng.com/#docs/module-loadermodule.exports.default=模块.exports;3.样式文件index.less两个UI库基本相同,都是将所有样式导入到同一个文件中,编译出来供用户使用。例如ivew:@import"./custom";@import"./mixins/index";@import"./common/index";@import"./animation/index";@import"./components/index";4.两个库组件的整体导入和按需导入1、整体导入:与两个库的方法相同。从“***”导入uiName;导入'***.css';Vue.use(用户名);这是因为源代码入口文件index.html采用了同样的方法:见上面第二个解释;2、按需导入:两个库都可以在全局组件上调用:import{Button,Table}from'***';Vue.component('Button',Button);Vue.component('Table',Table);但是引入elementUI之后,仍然可以这样调用:Vue.use(Button)Vue.use(Select)这是因为elementUI在各个组件上使用了install方法,而ivew是没有用的,不能用。使用
