一, 图示说明:
1. 在后续的业务开发中,经常会用到一个类似下图的工具栏,可作为公共组件进行封装,方便复用
2.上面的这一块就全局使用,写一个大概的构架,下面圈起来的部分就哪个页面就使用插槽嘛,去加入
自己想改的样式呗

二 . 封装组件以及用插槽使用组件
1. 封装组件:
在src/components下面补充创建 PageTools/index.vue (准备被别的组件引入的),
内容如下:
<template><el-card><div class="page-tools"><!-- 左侧 --><div class="left"><div class="tips"><i class="el-icon-info" /><span>文字区域</span></div></div><div class="right"><!-- 右侧 -->按钮区域</div></div></el-card></template><script>export default {}</script><style lang="scss" scoped>.page-tools {display: flex;justify-content: space-between;align-items: center;.tips {line-height: 34px;padding: 0px 15px;border-radius: 5px;border: 1px solid rgba(145, 213, 255, 1);background: rgba(230, 247, 255, 1);i {margin-right: 10px;color: #409eff;}}}</style>
出来就是这样的:

2. 引入插槽让用户能自定义内容(直接到这一步来吧!)

说明:
上面我们使用了两个具名插槽,将来在使用组件的时候,只需要按照对应的插槽名称就可
以在特定的位置插入内容。
3. 使用组件
我们在员工管理的业务组件内部直接通过使用局部组件的方式将page-tools使用起来,
并注入自定义内容。
设置 src/views/employees/employees.vue, 内容如下:

小结:
1.定义组件时,在template中用slot 定义插槽2.使用组件时,通过<组件> 传入结构 </组件>
三: 用 Vue.use — 全局使用工具栏组件
掌握Vue.use()的用法,能用它来注册全局组件;
1. 步骤:
1. 在 src/componets/index.js 里面统一注册的入口文件
import PageTools from './PageTools'export default {install(Vue) {Vue.component('PageTools', PageTools)}}
2.在 main.js 中注册插件
import Components from './components'Vue.use(Components)
所以,最后就不用再在组件里面导入注册了!!!

