Vue3 和 Vue2.6 的差异,和替代方案 Vue2.7
大纲链接 §
[toc]
1. 简记:Vue 3 对比 Vue 2 做了哪些改动? ⇧
v3-migration官方文档写了(中文在这),这里列出几个容易被考的:
- 原理层面:
- 使用 基于
Proxy(代替Object.definedProperty)的数据响应式系统
- 使用 基于
api层面- 使用
Composition api逻辑高内聚 - 实例化
const app = createApp(App)app.use().mount()代替了new Vue({})创建根实例const router = createRouter({});app.use(router);const pinia = createPinia({});app.use(pinia);const store = createStore({});app.use(store);
SFC(Single-File Component)单文件组件template模板语法糖<script setup>直接使用Composition api- 响应式数据(模块化)
ref和reactive destroyed被改名为unmounted了(before当然也改了)- 支持多根节点的组件,使用
fragment:<template> <CompA /> <CompB /></template>- 要求显式定义
$attrs应该分布在哪里:<template> <CompA v-bind="$attrs"/> <CompB /></template>
- 要求显式定义
v-model:value代替了以前的v-model和.sync- 新增内置组件
Teleport传送门 ref属性支持函数了ref="(el)=>{}"
- 使用
- 更易维护:
TypeScript+api模块化:支持局部导入 - 更易扩展:独立的响应化模块
- 兼容性:
Vue 3官方放弃对IE11的支持,需要兼容的话,使用Vue2.7
参考
使用 Vue 2.7 ⇧
IE8+
vue2.x部分配套生态
| Project | Status | Description |
|---|---|---|
| vue-router | Single-page application routing | |
| vuex | Large-scale state management | |
| vue-cli | Project scaffolding | |
| vue-loader | Single File Component (*.vue file) loader for webpack |
|
| vue-server-renderer | Server-side rendering support | |
| vue-class-component | TypeScript decorator for a class-based API | |
| vue-devtools | Browser DevTools extension |
参考文章 ⇧
相关文章 ⇧
- 作者: Joel
- 文章链接:
- 版权声明
- 非自由转载-非商用-非衍生-保持署名