最近做pc端业务用到了element-ui组件库,从引入到组件改造做个总结Element,一套为开发者、设计师和产品经理准备的基于 Vue 2.0 的桌面端组件库,整个ui风格简约,很实用,使用demo组件可以快速实现体验交互细节,快速开发1.安装,推荐npm方式安装npm i element-ui -S2.引入2.1全局引入,会把组件库里所有的组件和css引入import ElementUI from ’element-ui’; import ’element-ui/lib/theme-chalk/index.css’; Vue.use(ElementUI);2.2局部引入(推荐)由于业务的风格跟默认的颜色不一样,我采用了自定义主题,选择色号生成,在线生成工具(https://elementui.github.io/t…)可以很方便地实时预览主题色改变之后的视觉,同时它还可以基于新的主题色生成完整的样式文件包,供直接下载使用,在vue的入口js里直接引入主题样式element-variables.cssimport ‘@/style/theme/element-variables.scss’import { Message, MessageBox, Loading } from ’element-ui’Vue.use(Loading.directive)Vue.prototype.$loading = Loading.serviceVue.prototype.$msgbox = MessageBoxVue.prototype.$alert = MessageBox.alertVue.prototype.$confirm = MessageBox.confirmVue.prototype.$prompt = MessageBox.promptVue.prototype.$message = Message3.组件使用3.1像message。messagebox弹窗组件是直接挂载全局,因此在 Vue instance 中可以采用本页面中的方式调用 MessageBox。调用参数为:$msgbox(options) $alert(message, title, options) 或 $alert(message, options) $confirm(message, title, options) 或 $confirm(message, options) $prompt(message, title, options) 或 $prompt(message, options)具体使用:图片描述图片描述3.2 官网提供的dialog组件支持内容区更丰富的写法,dialog弹出一个对话框,适合需要定制性更大的场景。官网写法:图片描述这是最基础的使用,在这个基础上我做了个封装,将取消,确定函数挂在组件回调函数上,并且标题,宽度,显隐值都通过属性传递,可以让父组件引用较少的代码父组件:/* * 弹窗组件说明 * @param {object} dialogData: title-标题, width-宽度, dialogVisible-弹窗显隐状态 * @param {function} callback: 点确定位置的回调函数 * @param {function} closeDialog: 弹窗关闭的回调函数 * 示例: <OPdialog :dialog-data=“dialoginfo” @callback=“callback(item.taskinfo.taskDetail.taskid)” @closeDialog=“closeDialog”/> */<OPdialog :dialog-data=“dialoginfo” @callback=“callback(item.taskinfo.taskDetail.taskid)” @closeDialog=“closeDialog”/>子组件:<template> <div> <el-dialog v-if=“dialogData.dialogtype==‘confirm’” :visible.sync=“dialogData.dialogVisible” :modal-append-to-body=“false” :close-on-click-modal=“false” :width=“dialogData.width” top=“33vh” center @close=“closeDialog”> <p class=“dialog-body”>{{ dialogData.title }}</p> <span slot=“footer” class=“dialog-footer”> <el-button size=“medium” type=“primary” @click=“ok()">确定</el-button> <el-button size=“medium” @click=“dialogData.dialogVisible = false”>取 消</el-button> </span> </el-dialog> </div></template>