1、vue.js v3设计初衷
2、3.0版本有何优势?
3、相比于vue2的移除
4、相比于vue2的新增
5、vue3 项目初始化及注意事项
6、Vue3 Hook对比React Hook


vue.js v3设计初衷

Vue是一套用于构建用户界面的渐进式框架,7月18号,Vue.js 作者尤雨溪宣布 Vue 3 已进入RC 阶段,在9月份,正式发布release版本。

缺点:

  • 无法检测到数组的下标和length属性的变更,无法检测到对象属性的动态添加和删除
  • 复杂组件难以复用
  • 响应化过程需要递归遍历消耗较大
  • 项目过大维护任务艰巨

3.0版本有何优势

1.Performance

虚拟Dom初始化,ssr,更新效率

2.definePropety => JS Proxies

缺点:ie11

3.Tree-shaking support

* Vue.observable (用 Vue.reactive 替换)
* Vue.nextTick
* Vue.version
* Vue.compile
* Vue.set
* Vue.delete

4..Composition API ★

5.Better TypeScript support

6.Custom Renderer API

...


相比vue2的移除

1、API方面

* $on
* .$once
* $off
* Vue.config.productionTip
* 内联模板  attribute
* $destroy 实例方法

2、生命周期

* beforeDestroy
* destroyed

3、过滤器

* filters

4、修饰符

* 键码作为 v-on 修饰符
//局部

//全局
Vue.config.keyCodes = {
  f1: 112
}
* v-bind的 .sync

5、props里默认函数访问this

6、solt

// 2.x 语法
this.$scopedSlots.header

7、组件的 model 选项

8、eventBus =>mitt

...

相比vue2的新增

1、目录树形图

file
file

2、Main.js

import { createApp } from 'vue'
import App from './App.vue'
const app = createApp(App)
app.config.ignoredElements = [/^app-/]
app.use(/* ... */)
app.component(/* ... */)
app.directive(/* ... */)
app.mount('#app')

3、自定义指令

//2.0
const MyDirective = {
  bind(el, binding, vnode, prevVnode) {},
  inserted() {},
  update() {},
  componentUpdated() {},
  unbind() {}
}
//3.x
const MyDirective = {
  beforeMount(el, binding, vnode, prevVnode) {},
  mounted() {},
  beforeUpdate() {},
  updated() {},
  beforeUnmount() {}, // new
  unmounted() {}
}

4、$on.$once.$off 移除,$emit保留

5、setup() 函数

生命周期 beforeCreate beforeCreate
setup
created created
beforeMount onBeforeMount
mounted onMounted
beforeUpdate onBeforeUpdate
updated onUpdated
beforeDestroy onBeforeUnmount
destroyed onUnmounted
errorCaptured onErrorCaptured
onRenderTracked
onRenderTriggered
setup(props,context) {
    /*                   attrs   isServer
     *  contenxt =>      emit     listeners  ssrContent
    */                   parent   refs
                         root     slots
}
* ref
* context

6.Fragment多根节点

7.Teleport ()


  

Tooltips with Vue 3 Teleport<./h3>
<./modal-button>

const app = Vue.createApp({}); app.component('modal-button', { template: `