1.Vue3.0六大亮点
- Performance:性能比Vue 2.x快1.2~2倍
- Tree shaking support:按需编译,体积比Vue2.x更小
- Composition API: 组合API(类似React Hooks)
- Better TypeScript support:更好的 Ts 支持
- Custom Renderer API:暴露了自定义渲染API
- Fragment, Teleport(Protal), Suspense:更先进的组件
来说一说为什么Performance:性能比Vue 2.x快1.2~2倍
2.那么Vue3.0是如何变快的?
这里先提供两个网址:
-
vue2.xx版本在线编译:
https://template-explorer.vuejs.org/# -
vue3.xx版本在线编译:
https://vue-next-template-explorer.netlify.app/#
2.1 diff算法优化:
- Vue2中的虚拟dom是进行全量的对比
- Vue3新增了静态标记(PatchFlag),
在与上次虚拟节点进行对比时候,只对比带有patch flag的节点
并且可以通过flag的信息得知当前节点要对比的具体内容
例子: