前言:在2019.10.05發(fā)布了vue3.0預(yù)覽版源碼,預(yù)計(jì)在2020年第一季度才有可能發(fā)布正式版本。
ps:我們都知道,vue2,基于defineProperty 有很多遞歸去定義get,set 在性能上有一些消耗
新版vue3.0改用proxy,也代表著vue放棄兼容ie,計(jì)劃主要更新和功能如下:
一、編譯器
1.使用模塊化架構(gòu)
2.優(yōu)化"Block tree"
3.更激進(jìn)的static tree hoisting 功能(檢測(cè)靜電語法,進(jìn)行提升)
4.支持Source map
5.內(nèi)置標(biāo)識(shí)符前綴(又名‘StripWith’)
- ......
二、運(yùn)行時(shí)
1.速度顯著提升
2.同時(shí)支持Composition Api,以及typings
3.基于Proxy 實(shí)現(xiàn)的數(shù)據(jù)變更檢測(cè)
4.支持Suspense w/ async setup{}
- ......
(目前不支持IE11)
三、剖析Vue Composition API(vue3.0核心api,都是基于函數(shù)方式的)(https://vue-composition-api-rfc.netlify.com)
1.vue 3 使用ts實(shí)現(xiàn)了類型推斷,新版api全部采用普通函數(shù) 讓編寫代碼時(shí)可以享受完整的類型推斷(避免裝飾器);
2.解決了多組件間邏輯重用問題(解決:高階組件、mixin、作用域插件);
3.composition api 使用簡(jiǎn)單
<template>
<button @click="increment">
Count is: {{ state.count }}, double is: {{ state.double }}
</button>
</template>
<script>
import { reactive, computed } from 'vue'
export default {
setup() {
const state = reactive({
count: 0,
double: computed(() => state.count * 2)
})
function increment() {
state.count++
}
return {
state,
increment
}
}
}
</script>
四、先把源碼down下來(https://github.com/vuejs/vue-next
)