<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          Vue 3.1.0 的 beta 版發(fā)布

          共 8382字,需瀏覽 17分鐘

           ·

          2021-05-15 10:26

          以往都是純翻譯發(fā)給大家,這次換個形式為大家介紹。

          編輯 | KnowsCount

                   QC-L

          本次 beta 版本帶來了一些有趣的新特性和錯誤修復(fù)。

          新特性

          • onServerPrefetch:composition-api 版本的 serverPrefetch
          • 組件級別的 compilerOptions
          • @vue/compiler-core 支持了空白字符處理策略
          • 支持通過 app.config.compilerOptions 配置運行時的編譯器
          • devtools 改進了對 KeepAlive 的支持
          • 支持通過 is="vue:xxx" 將普通元素轉(zhuǎn)換為組件

          onServerPrefetch

          具體請參見 PR 3070[1]PR 2902[2]

          此特性主要解決在 composition-api 情況下沒有提供 serverPrefetch 生命周期鉤子函數(shù)的問題。

          這個鉤子函數(shù)名為 onServerPrefetch。

          如果你也這方面的需求,可以嘗試升級至 3.1.0-beta

          相關(guān)討論:

          • vue-apollo[3]
          • app-extension-apollo[4]

          @vue/complier-core 支持了空白字符處理策略

          具體內(nèi)容請參閱 PR 1600[5]v2 原有效果[6]。

          應(yīng)用

          我們來測試下此策略:

          先裝個 beta 版本的 @vue/compiler-core

          yarn add @vue/compiler-core@beta

          新建 index.js 文件

          const core = require('@vue/compiler-core')

          const { baseCompile: complie } = core

          const { ast } = complie(`      foo \n bar baz      `, {
            whitespace'preserve' // condense
          })

          console.log(ast.children[0])
          console.log(ast.children[0].content)

          大概效果如示例所示:

          <!-- 源代碼 -->
                foo \n bar baz     

          <!-- whitespace: 'preserve' -->
                foo \n bar baz     

          <!-- whitespace: 'condense' -->
           foo bar baz 

          源碼

          原本只在 compiler-coreparse 文件中的 defaultParserOptions 提供了默認的 condense 情況

          whitespace: 'condense'

          compiler-core 的 options 文件中新增了 whitespace

          whitespace?: 'preserve' | 'condense'

          相關(guān)鏈接:

          • PR 1600[7]
          • stackoverflow[8]
          • vue 2.0/compiler[9]
          • vue 2.0 的 `whitespace`[10]
          • vue 2.0 的 PR[11]

          通過 is="vue:xxx" 支持普通元素的轉(zhuǎn)換

          這條特性的更新,從源碼上看,兼容了兩種類型。

          1. 棄用的 v-is 指令
          2. is="vue:xxx" 的屬性

          源碼


          let { tag } = node

          // 1. 動態(tài)組件
          const isExplicitDynamic = isComponentTag(tag)
          const isProp =
            findProp(node, 'is') || (!isExplicitDynamic && findDir(node, 'is'))
          if (isProp) {
            if (!isExplicitDynamic && isProp.type === NodeTypes.ATTRIBUTE) {
              // <button is="vue:xxx">
              // 如果不是 <component>,僅僅是 "vue:" 開頭
              // 在解析階段會被視為組件,并在此處進行
              // tag 被重新賦值為 "vue:" 以后的內(nèi)容
              tag = isProp.value!.content.slice(4)
            } else {
              const exp =
                isProp.type === NodeTypes.ATTRIBUTE
                  ? isProp.value && createSimpleExpression(isProp.value.content, true)
                  : isProp.exp
              if (exp) {
                return createCallExpression(context.helper(RESOLVE_DYNAMIC_COMPONENT), [
                  exp
                ])
              }
            }
          }
          // 當(dāng) tag 為 <component>,或者 is="vue:xxx",跳過后續(xù)處理
          if (
            name === 'is' &&
            (isComponentTag(tag) || (value && value.content.startsWith('vue:')))
          ) {
            continue
          }
          // ...

          上述代碼中有幾個點:

          1. 首先 isComponentTag,用以判斷是否為動態(tài)組件:
          // 此方法用于判斷是否為動態(tài)組件
          function isComponentTag(tag: string{
            return tag[0].toLowerCase() + tag.slice(1) === 'component'
          }
          1. 查找是否含有 is 屬性
          // 先查屬性
          findProp(node, 'is')
          // 否則判斷是不是動態(tài)組件,如果不是,判斷是不是指令
          !isExplicitDynamic && findDir(node, 'is')

          其主要原因是,兩者的 AST 結(jié)構(gòu)不同。

          相關(guān)鏈接:

          • Support casting plain element[12]
          • Custom Elements Interop[13]

          附上 ChangeLog

          Bug 修復(fù)

          • 兼容: 處理并針對 config.optionMergeStrategies 實現(xiàn)告警 (94e69fd[14])
          • compiler-core: 當(dāng)注釋選項啟用時,在生產(chǎn)環(huán)境下將保留注釋 (e486254[15])
          • hmr: 禁止從組件類型中移除 __file 的 key 值 (9db3cbb[16])
          • hydration: 修復(fù) asnyc 組件 hydrated 前的更新 (#3563[17]) (c8d9683[18]), closes #3560[19]
          • reactivity: 修復(fù) readonly + reactive Map 的追溯 (#3604[20]) (5036c51[21]), closes #3602[22]
          • runtime-core: 確保聲明 props 的 key 永遠存在 (4fe4de0[23]), closes #3288[24]
          • runtime-core: computed 監(jiān)聽多個 source (#3066[25]) (e7300eb[26]), closes #3068[27]
          • Teleport: 避免改變對 vnode.dynamicChildren 的引用 (#3642[28]) (43f7815[29]), closes #3641[30]
          • watch: 避免遍歷 non-plain 對象 (62b8f4a[31])
          • watch: this.$watch 應(yīng)該支持監(jiān)聽鍵路徑 (870f2a7[32])

          特性

          • onServerPrefetch (#3070[33]) (349eb0f[34])
          • 運行時編譯器支持了組件級 compilerOptions (ce0bbe0[35])
          • compiler-core: whitespace 處理策略 (dee3d6a[36])
          • config: 利用 app.config.compilerOptions 支持配置運行時編譯器 (091e6d6[37])
          • devtools: 升級對 KeepAlive 的支持 (03ae300[38])
          • 支持利用 is="vue:xxx" 將 plain 元素 cast 到組件 (af9e699[39])

          性能提升

          • 僅當(dāng)實際改變時才會觸發(fā) $attrs 的更新 (5566d39[40])
          • compiler: 解析結(jié)束標簽時跳過不必要的檢查 (048ac29[41])

          參考資料

          [1]

          PR 3070: https://github.com/vuejs/vue-next/pull/3070

          [2]

          PR 2902: https://github.com/vuejs/vue-next/pull/2902

          [3]

          vue-apollo: https://github.com/vuejs/vue-apollo/issues/1102

          [4]

          app-extension-apollo: https://github.com/quasarframework/app-extension-apollo/issues/51#issuecomment-791977057

          [5]

          PR 1600: https://github.com/vuejs/vue-next/pull/1600

          [6]

          v2 原有效果: https://github.com/vuejs/vue/blob/dev/flow/compiler.js#L10

          [7]

          PR 1600: https://github.com/vuejs/vue-next/pull/1600

          [8]

          stackoverflow: https://stackoverflow.com/questions/64432182/vue-3-removes-white-space-between-inline-block-elements

          [9]

          vue 2.0/compiler: https://github.com/vuejs/vue/blob/dev/flow/compiler.js#L10

          [10]

          vue 2.0 的 whitespace: https://github.com/vuejs/vue/issues/9208#issuecomment-450012518

          [11]

          vue 2.0 的 PR: https://github.com/vuejs/vue/commit/e1abedb9e66b21da8a7e93e175b9dabe334dfebd

          [12]

          Support casting plain element: https://github.com/vuejs/vue-next/commit/af9e6999e1779f56b5cf827b97310d8e4e1fe5ec

          [13]

          Custom Elements Interop: https://v3.vuejs.org/guide/migration/custom-elements-interop.html

          [14]

          94e69fd: https://github.com/vuejs/vue-next/commit/94e69fd3896214da6ff8b9fb09ad942c598053c7

          [15]

          e486254: https://github.com/vuejs/vue-next/commit/e4862544310a4187dfc8b3a49944700888bb60e3

          [16]

          9db3cbb: https://github.com/vuejs/vue-next/commit/9db3cbbfc1a072675a8d0e53edf3869af115dc60

          [17]

          #3563: https://github.com/vuejs/vue-next/issues/3563

          [18]

          c8d9683: https://github.com/vuejs/vue-next/commit/c8d96837b871d7ad34cd73b4669338be5fdd59fd

          [19]

          #3560: https://github.com/vuejs/vue-next/issues/3560

          [20]

          #3604: https://github.com/vuejs/vue-next/issues/3604

          [21]

          5036c51: https://github.com/vuejs/vue-next/commit/5036c51cb78435c145ffea5e82cd620d0d056ff7

          [22]

          #3602: https://github.com/vuejs/vue-next/issues/3602

          [23]

          4fe4de0: https://github.com/vuejs/vue-next/commit/4fe4de0a49ffc2461b0394e74674af38ff5e2a20

          [24]

          #3288: https://github.com/vuejs/vue-next/issues/3288

          [25]

          #3066: https://github.com/vuejs/vue-next/issues/3066

          [26]

          e7300eb: https://github.com/vuejs/vue-next/commit/e7300eb47960a153311d568d7976ac5256eb6297

          [27]

          #3068: https://github.com/vuejs/vue-next/issues/3068

          [28]

          #3642: https://github.com/vuejs/vue-next/issues/3642

          [29]

          43f7815: https://github.com/vuejs/vue-next/commit/43f78151bfdff2103a9be25e66e3f3be68d03a08

          [30]

          #3641: https://github.com/vuejs/vue-next/issues/3641

          [31]

          62b8f4a: https://github.com/vuejs/vue-next/commit/62b8f4a39ca56b48a8c8fdf7e200cb80735e16ae

          [32]

          870f2a7: https://github.com/vuejs/vue-next/commit/870f2a7ba35245fd8c008d2ff666ea130a7e4704

          [33]

          #3070: https://github.com/vuejs/vue-next/issues/3070

          [34]

          349eb0f: https://github.com/vuejs/vue-next/commit/349eb0f0ad78f9cb491278eb4c7f9fe0c2e78b79

          [35]

          ce0bbe0: https://github.com/vuejs/vue-next/commit/ce0bbe053abaf8ba18de8baf535e175048596ee5

          [36]

          dee3d6a: https://github.com/vuejs/vue-next/commit/dee3d6ab8b4da6653d15eb148c51d9878007f6b6

          [37]

          091e6d6: https://github.com/vuejs/vue-next/commit/091e6d67bfcc215227d78be578c68ead542481ad

          [38]

          03ae300: https://github.com/vuejs/vue-next/commit/03ae3006e1e678ade4377cd10d206e8f7b4ad0cb

          [39]

          af9e699: https://github.com/vuejs/vue-next/commit/af9e6999e1779f56b5cf827b97310d8e4e1fe5ec

          [40]

          5566d39: https://github.com/vuejs/vue-next/commit/5566d39d467ebdd4e4234bc97d62600ff01ea28e

          [41]

          048ac29: https://github.com/vuejs/vue-next/commit/048ac299f35709b25ae1bc1efa67d2abc53dbc3b


          瀏覽 63
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          分享
          舉報
          評論
          圖片
          表情
          推薦
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          分享
          舉報
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  丰润少妇在线观看视频 | а√中文在线资源库 | 五月四色 | 北条麻妃丝袜电影 | 男人的天堂资源网 |