1.插槽
1.1组件插槽
- 作用:让组件内的标签能动态传入。给组件插入什么标签,组件就显示什么标签。没传就用默认内容,传了就会替换
- 使用方法:
- 子组件内用slot标签占位
- 使用组件时pannel标签夹着的地方,传入标签替换slot。(pannel是子组件名)
- 如果外面不给传,就在slot标签内传入默认内容
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/d876a692cb1fe9252506b3120a2089ad.png)
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/c33ce354563f3ad540cf8c36934d7cb0.png)
1.2具名插槽
- 一个组件内有两处以上需要外部传入标签的地方
- 使用方法:
- 子组件内给slot标签设置name属性区分名字
- 父组件内template配合v-slot
- v-slot可以简写为 #插槽名
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/65a48bfefb1b2738c242a50c99734b17.png)
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/dcea72297fcb97547cea8aa33b3d0e96.png)
1.3作用域插槽
- 使用插槽时,想使用子组件内变量
- 使用方法:
- 子组件内给slot 绑定属性和子组件的值
- 父组件内template 配合v-slot
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/05ed61731f9ee8e51472ea0c475c854c.png)
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/da4471f53b7188224ed1365f5f5b1e11.png)
1.4具名插槽和作用域插槽一起使用
- 写法:v-slot:title=“scope”
- 简写:#title=“scope”
2.自定义指令-注册
- 当 Vue 内置指令无法满足需求时可以自定义
- 全局注册,写在main.js 里
Vue.directive('foc',{
inserted(el){
el.focus()
}
})
directives:{
foc: