Vue
应用入口/全局API
分类 | Composition / Options API(Vue3) | Options API(Vue2) |
---|---|---|
客户端渲染 | createApp() v3.0 | new Vue() v2.0 |
挂载 | app.mount() v3.0 | $mount() v2.0 |
卸载 | app.unmount() v3.0 | $destroy() v2.0 |
- | app.onUnmount() v3.5 | 同上 |
配置设置 | app.config v3.0 | Vue.config v2.0 |
版本 | app.version v3.0 | Vue.version v2.0 |
创建组件
分类 | Composition API(Vue3) | Options API(Vue3) | Options API(Vue2) |
---|---|---|---|
创建 | - | SFC v3.0 | SFC v2.0 |
- | - | - | functional v2.5 functional v2.0 |
- | defineComponent() v3.0 | - | new Vue() v2.0 Vue.extend() v2.0 |
注册 | app.component() v3.0 | - | Vue.component() v2.0 components v2.0 |
懒加载 | defineAsyncComponent() v3.0 | - | import() v2.0/ES2020 |
\-加载状态 | defineAsyncComponent() v3.0 | - | loading v2.3 |
\-回退方案 | <Suspense> | - | - |
\-动态组件 | <component> v3.0 | - | <component> v2.0 |
性能优化 | <KeepAlive> v3.0 | - | <keep-alive> v2.0 |
\-记忆渲染结果 | - | v-memo v3.2 | - |
\-渲染一次 | - | v-once v3.0 | v-once v2.0 |
组件生命周期方法
分类 | Composition API(Vue3) | Options API(Vue3) | Options API(Vue2) |
---|---|---|---|
创建 | 无 | beforeCreate() v3.0 | beforeCreate() v2.0 |
- | 无 | created() v3.0 | created() v2.0 |
挂载 | onBeforeMount() v3.0 | beforeMount() v3.0 | beforeMount() v2.0 |
- | onRenderTracked() - DEV v3.0 | renderTracked() - DEV v3.0 | 无 |
- | onMounted() v3.0 | mounted() v3.0 | mounted() v2.0 |
更新 | onRenderTriggered() - DEV v3.0 | renderTriggered() - DEV v3.0 | 无 |
- | onBeforeUpdate() v3.0 | beforeUpdate() v3.0 | beforeUpdate() v2.0 |
- | onDeactivated() v3.0 | deactivated() v3.0 | deactivated() v2.0 |
- | onActivated() v3.0 | activated() v3.0 | activated() v2.0 |
- | onUpdated() v3.0 | updated() v3.0 | updated() v2.0 |
卸载 | onBeforeUnmount() v3.0 | beforeUnmount() v3.0 | beforeDestroy() v2.0 |
- | onUnmounted() v3.0 | unmounted() v3.0 | destroyed() v2.0 |
错误捕获 | onErrorCaptured() v3.0 | errorCaptured() v3.0 | errorCaptured() v2.5 |
SSR | onServerPrefetch() v3.0 | serverPrefetch() v3.0 | 无 |
组件属性
分类 | Composition API(Vue3) | Options API(Vue3/2) |
---|---|---|
声明 | defineProps() v3.0 | props v2.0 |
属性默认值 | withDefaults() v3.0 | 同上 |
读取 | useAttrs() v3.0 | $attrs v2.4 |
- | var props v3.0 | $props v2.2 |
绑定 | v-bind v3.0 | v-bind v2.0 |
透传 | defineOptions() v3.3 | inheritAttrs v2.4 |
- | app.config.globalProperties v3.0 | Vue.prototype v2.0 |
- | app.config.optionMergeStrategies v3.0 | Vue.config.optionMergeStrategies v2.0 |
- | $options v3.0 | $options v2.0 |
Children 属性 | - | $children v2.0 |
组件状态
分类 | Composition API(Vue3) | Options API(Vue3) | Options API(Vue2) |
---|---|---|---|
声明 | ref() v3.0 | data v3.0 | data v2.0 |
读取 | - | $data v3.0 | $data v2.0 |
更新 | computed() v3.0 | computed v3.0 | computed v2.0 |
监听 | watch() v3.0 | watch v3.0 | watch v2.0 |
- | - | $watch() v3.0 | $watch() v2.0 |
- | watchEffect() v3.0 | - | - |
- | watchPostEffect() v3.0 | - | - |
- | watchSyncEffect() v3.0 | - | - |
- | onWatcherCleanup() v3.5 | - | - |
- | effectScope() v3.0 | - | - |
- | getCurrentScope() v3.0 | - | - |
- | onScopeDispose() v3.0 | - | - |
组件事件
分类 | Composition API(Vue3) | Options API(Vue3) | Options API(Vue2) |
---|---|---|---|
事件及类型声明 | defineEmits() v3.0 | emits v3.0 | emits v2.7 |
\-回调 | - | methods v3.0 | methods v2.0 |
触发 | var emit() v3.0 | $emit() v3.0 | $emit() v2.0 |
- | - | - | $listeners v2.4 |
绑定 | - | @ / v-on v3.0 | @ / v-on v2.0 |
- | - | @/v-on | $on v2.0 |
- | - | .once v3.0 | $once v2.0 |
- | - | 组件卸载自动完成 | $off |
DOM 事件对象 | - | $event v3.0 | $event v2.0 |
表单输入
分类 | Composition API(Vue3) | Options API(Vue3) | Options API(Vue2) |
---|---|---|---|
双向绑定 | - | v-model v3.0 | v-model v2.0 |
- | defineModel() v3.4 useModel() v3.4 | - | model v2.2 |
组件渲染
模板
指令
分类 | Composition API(Vue3) | Options API(Vue3) | Options API(Vue2) |
---|---|---|---|
条件渲染 | - | v-if v3.0 | v-if v2.0 |
- | - | v-else-if v3.0 | v-else-if v2.0 |
- | - | v-else v3.0 | v-else v2.0 |
列表渲染 | - | v-for v3.0 / :key v3.0 | v-for v2.0 / :key v2.0 |
显示隐藏 | - | v-show v3.0 | v-show v2.0 |
文本渲染 | - | v-text v3.0 | v-text v2.0 |
HTML渲染 | - | v-html v3.0 | v-html v2.0 |
跳过编译 | - | v-pre v3.0 | v-pre v2.0 |
隐藏未编译插值 | - | v-cloak v3.0 | v-cloak v2.0 |
渲染一次 | - | v-once v3.0 | v-once v2.0 |
缓存模板 | - | v-memo v3.2 | - |
注册指令 | - | directives v3.0 | directives v2.0 |
- | app.directive() v3.0 | - | Vue.directive() v2.0 |
插槽
分类 | Composition API(Vue3) | Options API(Vue3) | Options API(Vue2) |
---|---|---|---|
出口 | - | <slot> v3.0 | <slot> v2.0 |
声明 | defineSlots() v3.3 | slots v3.3 | - |
命名插槽 | - | 同上 | |
作用域插槽 | - | 同上 | |
- | - | 同上 | |
读取 | useSlots() v3.0 | $slots v3.0 | $slots v2.0 |
- | - | - | |
绑定 | - | v-slot v3.0 | v-slot v2.6 |
组件上下文
依赖注入
分类 | Composition API(Vue3) | Options API(Vue3) | Options API(Vue2) |
---|---|---|---|
创建和提供 | provide() v3.0 | provide v3.0 | provide v2.2 |
- | app.provide() v3.0 | - | - |
- | app.runWithContext() v3.3 | - | - |
读取和订阅 | - | - | - |
- | inject() v3.0 | inject v3.0 | inject v2.2 |
- | hasInjectionContext() v3.3 | - | - |
DOM 实例
分类 | Composition API(Vue3) | Options API(Vue3) | Options API(Vue2) |
---|---|---|---|
引用 | - | ref v3.0 | ref v2.0 |
\-获取 | ref.value | $refs v3.0 | $refs v2.0 |
- | - | $el v3.0 | $el v2.0 |
\-立即获取 DOM | nextTick() v3.0 | $nextTick() v3.0 | Vue.nextTick() v2.0 $nextTick() v2.0 |
\-查找 | - | $root v3.0 | $root v2.0 |
- | - | $parent v3.0 | $parent v2.0 |
\-挂载 | - | - | el v2.0 |
组件引用 | useTemplateRef() v3.5 | - | - |
\-属性公开 | defineExpose() v3.0 | expose v3.0 | - |
\-挂载 | <Teleport> v3.0 | - | - |
过渡和动画
分类 | Vue3 | Vue2 |
---|---|---|
过渡&动画 | <Transition> | <transition> |
- | <TransitionGroup> | <transition-group> |
异常处理
分类 | Composition API(Vue3) | Options API(Vue3) | Options API(Vue2) |
---|---|---|---|
类型检查 | TypeScript | - | 类型校验 |
错误捕获 | onErrorCaptured() v3.0 | errorCaptured() v3.0 | errorCaptured() v2.5 |
全局设置 | app.config.errorHandler v3.0 | - | Vue.config.errorHandler v2.0 |
- | app.config.warnHandler v3.0 | - | Vue.config.warnHandler v2.4 |
- | app.config. throwUnhandledErrorInProduction v3.5 | - | - |
Vue 日志与警告 | - | - | Vue.config.silent v2.0 |
Vue 生产提示 | - | - | Vue.config.productionTip v2.2 |
架构设计
可复用性
分类 | Composition API(Vue3) | Options API(Vue3) | Options API(Vue2) |
---|---|---|---|
插件 | app.use() v3.0 | - | Vue.use() v2.0 |
指令 | - | directives v3.0 | directives v2.0 |
- | app.directive() v3.0 | - | Vue.directive() v2.0 |
依赖注入 | provide() v3.0 | provide v3.0 | provide v2.2 |
- | app.provide() v3.0 | - | |
- | app.runWithContext() v3.3 | - | |
- | inject() v3.0 | inject v3.0 | inject v2.2 |
- | hasInjectionContext() v3.3 | - | - |
混入 | - | mixins v3.0 | mixins v2.0 |
- | app.mixin() v3.0 | - | Vue.mixin() v2.0 |
扩展 | - | extends v3.0 | extends v2.0 |
- | - | - | Vue.extend() v2.0 |
- | - | filters v2.0 | |
- | - | - | Vue.filter() v2.0 |
响应式
分类 | Composition API(Vue3) - Proxy | Options API(Vue2)- Object.defineProperty |
---|---|---|
响应式对象 | - | Vue.observable() v2.6 |
添加属性 | - | Vue.set() v2.0 |
\- | - | $set() v2.0 |
删除属性 | - | Vue.delete() v2.0 |
\- | - | $delete() v2.0 |
引用 | ref() v3.0 | data |
\- | isRef() v3.0 | - |
\- | unref() v3.0 | - |
\- | toRef() v3.3 | - |
\- | toRefs() v3.0 | - |
\- | toValue() v3.3 | - |
\- | shallowRef() v3.0 | - |
\- | triggerRef() v3.0 | - |
\- | customRef() v3.0 | - |
代理 | isProxy() v3.0 | - |
\- 响应式对象 | reactive() v3.0 | - |
\- | shallowReactive() v3.0 | - |
\- | isReactive() v3.0 | - |
\- 只读对象 | readonly() v3.0 | - |
\- | shallowReadonly() v3.0 | - |
\- | isReadonly() v3.0 | - |
原始对象 | toRaw() v3.0 | - |
\- | markRaw() v3.0 | - |
性能优化
分类 | Composition / Options API(Vue3) | Options API(Vue2) |
---|---|---|
分析 | app.config.performance v3.0 | Vue.config.performance v2.2 |
- | Chrome DevTools - performance | - |
- | - | Vue.config.devtools v2.0 |
- | Vue DevTools - performance | - |
优化 | - | - |
\-逻辑优化 | v-once | - |
- | v-memo | - |
- | key | - |
- | computed() | - |
- | watchEffect() | - |
- | onWatcherCleanup() | - |
- | <KeepAlive> | <keep-alive> |
- | shallowRef() | - |
- | shallowReactive() | - |
\-资源加载 | defineAsyncComponent() | import() |