动态组件
1.vue内置<component>组件 相当于一个占位符,它的is属性的值是要显示的组件
在运行时发现一个问题,每次控制组建的显隐时都会触发created,destory函数,为了防止这样的消耗,
使用keep-alive,解决。其中include是名称匹配的缓存,exclude是名称匹配的不缓存
eg:
<keep-alive exclude="MyRight">
<!-- 渲染 Left 组件和 Right 组件 -->
<component :is="conName">
</component>
</keep-alive>
2.组件声明时可以传入name属性,若没有传入,则默认为注册名称
eg
<keep-alive exclude="MyRight">
<!-- 渲染 Left 组件和 Right 组件 -->
<component :is="conName">
</component>
</keep-alive>
<keep-alive exclude="Right">
<!-- 渲染 Left 组件和 Right 组件 -->
<component :is="conName">
</component>
</keep-alive>
第一个是Right传过去name值了,所以是MyRight。
第二个是Right没有传name值,所以是Right
3.注册名:以标签形式把组件渲染到页面
name:结合<keep-alive>标签实现组件缓存功能

浙公网安备 33010602011771号