<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>

          Vue2升級到Vue3到底是不是一個正確的選擇?(尤雨溪親自回復解讀)

          共 5250字,需瀏覽 11分鐘

           ·

          2022-07-13 14:33

          作者:掘金干貨君

          原文:https://juejin.cn/post/7117525259212816414

          就在前兩天,一篇反對Vue2升級到Vue3的文章在vue官方社區(qū)引起了熱議。(原文鏈接:Vue 3 was a mistake that we should not repeat[1]

          這篇文章從實際應用角度出發(fā),分析了Vue2Vue3在真實項目中實操升級的痛點,提出了一個反對的聲音:Vue3的升級是一個錯誤的選擇

          在一片熱議中,甚至尤大都出來親自解釋并承認了一些問題。本文列舉了一些原文中提到的觀點以及尤大的回復。希望能給各位讀者在實際項目升級時,提供更實際全面的參考。

          前言

          原作者首先聲明了他并沒有貶低Vue3的意思。他認為Vue3是非常非常棒的框架,解決了Vue2中很多潛在問題,技術(shù)層面改善了開發(fā)人員的開發(fā)體驗,并顯著提高了性能。原作者主要的問題,是從Vue3突破性的改變以及周邊生態(tài)圈未能及時跟上的角度,重點強調(diào)了遷移升級成本+風險較大。

          關(guān)于升級成本問題:尤大也承認了Vue3升級體驗并沒有想象中的那么流暢,Vue4會吸取經(jīng)驗,做好平穩(wěn)迭代。這一點本文會在下面詳細說明。

          接下來,我們針對原文中提到的觀點逐一列舉解讀。

          ps: 為了避免語言翻譯差異問題,所有原作者尤大的觀點都是附上英語原文。

          一、破壞性的api變更(Breaking changes)

          • Events API[2]的棄用讓這個問題首當其沖。(straightforward like the depreciation of the Events API)。Vue實例再也不能作為事件總線做事件通信,$on,$off,$once的徹底移除意味著之前所有有關(guān)代碼都必須重新推翻重寫,雖然有很好的插件工具讓這件事變得沒那么復雜,但是仍然會帶來不小的遷移成本。
          • 代碼構(gòu)建問題。 你會經(jīng)常遇到用Vue2寫法寫出來的代碼在構(gòu)建(build) 失敗或拋出警告。因為這些api寫法在Vue3中已經(jīng)被廢棄。這問題在已存在的大型項目中的尤為突出(In an existing large-scale application built with Vue 2, you would probably use some of the deprecated or changed APIs)。下圖展示了一部分Breaking changes,可以看到破壞性的api變更數(shù)確實很多:
          image.png

          二、顛覆式的設(shè)計模式(composition-api)

          顛覆式的composition-api慢慢向面向函數(shù)思想轉(zhuǎn)變,導致很多原有習慣于options-api的開發(fā)者反感Vue正在像react靠攏,沒有堅持住Vue特色。它提出了一種新的基于函數(shù)的 Vue 組件編寫方式,引起了Vue社區(qū)大量的爭議和分裂,甚至將社區(qū)分隔為兩種觀點陣營針鋒相對,最終導致了Vue 最黑暗的一天事件[3]。這很令人沮喪。

          (the Request for Comment for the new function-based way of writing Vue components which had an overwhelming amount of responses, both positive and negative.No matter where you stand in this argument splitting the community in half is never a good sign and led to Vue’s Darkest Day and a lot of people getting discouraged over this.)

          三、生態(tài)系統(tǒng)(The ecosystem)

          框架的真正力量來自社區(qū)和它周圍的生態(tài)系統(tǒng)。(The true power of a framework comes from the community and the ecosystem around it.)

          生態(tài)系統(tǒng)和框架本身一樣重要。因為沒有責任機制,在有爭議的決定和在棄用功能的時候,很多框架周邊的生態(tài)系統(tǒng)的許多貢獻者會被迫離開,并導致許多庫被放棄或者延遲更新。很多時候,我們沒有辦法做版本兼容時,我們往往只能把責任歸咎于,開源庫缺乏同理心和對大局的理解。(Controversial decisions and no accountability while deprecating features drove many contributors away and resulted in many libraries being abandoned. But blaming open source libraries for delays when you don't give them a feasible way to support both versions shows a lack of empathy and lack of understanding of the bigger picture)

          四、文檔系統(tǒng)(Documentation)

          在我們的日常開發(fā)中,尤其是在使用框架時,我們會遇到各種各樣的問題,這時我們時常需要google或者問答社區(qū)作為幫手,但是目前關(guān)于Vue搜索出來的結(jié)果幾乎全是Vue2的結(jié)果,這也很難不令人難過。

          (During development, especially with a new framework, Google and StackOverflow are your best friends. Currently, Vue 2 answers are dominating the results which might cause confusion and frustration since many things don’t work the same in Vue 3.)

          五、過往案例(The past)

          Vue2到Vue3的升級,有一點像angular1到angular2的升級

          過渡到 Vue 3 看起來很像從AngularJS過渡到Angular版本 1? 2)。大量的延遲和重大更改導致了挫敗感,最終 Angular 失去了對 React 和 Vue 的吸引力。

          (The transition to Vue 3 looks a lot like the transition from AngularJS to Angular (Version 1? 2). A lot of delays and breaking changes led to frustration and eventually Angular lost traction to React and Vue.)

          五、結(jié)論(Apinion)

          1. 看起來前進的道路其實是倒退。(It looks like the way forward is going backwards)
          2. 開發(fā)滿意度看起來并不好[4]。(development satisfaction is not looking good)

          上圖可以看到Vue已經(jīng)有被svelte超越的趨勢。

          1. Vue4應該考慮到整個生態(tài)系統(tǒng)并提供遷移路徑,否則它將成為沒有人愿意使用的最佳框架。(Vue 4 should take into account the whole ecosystem and provide a migration path or it will be the best framework that no one will want to use.)

          六、尤大的回復:

          1.關(guān)于破壞性的api:

          這根本不是真的。

          當我們進行版本切換時,所有核心庫和工具都與這兩個版本兼容(或為 Vue 2/3 支持提供單獨的版本)。

          實際上阻礙升級的依賴都是第三方,主要是 NuxtVuetify

          2.顛覆式的設(shè)計模式:

          實際使用過 Composition API + < script setup> 的用戶在真是開發(fā)中的反饋非常積極,證明這是一個有價值的補充,現(xiàn)在他們中的許多人更喜歡它而不是 Options API。

          我們當然可以更好地處理新 API 的引入,但僅僅因為存在爭議,并不意味著它是錯誤的或者不必要的。實際上,引入大的、新的想法的行為,勢必會讓那些喜歡呆在舒適區(qū)的人感到不安,但如果我們迎合這種心態(tài),就永遠不會取得真正的進展。

          3.關(guān)于周邊生態(tài)和文檔系統(tǒng):

          雖然我們確實創(chuàng)造了 Vue CLI、Vuex、Vetur 和 VuePress 的新替代品,但它們本身都有適用于 Vue 3 的版本。這是夸大事實,不尊重團隊為提供這些工具的 Vue 3 兼容版本所做的努力。

          4.關(guān)于和angular的過往對比:

          • 沒有可比性,不能拿Vue升級和angularjs -> angular做對比。
          • Angular 和 AngularJS 是根本不同的框架。幾乎沒有共享交集,除了完全重寫之外沒有實際的遷移路徑。
          • 另一方面,有許多生產(chǎn) Vue 2 應用程序成功遷移到 Vue 3 的案例。很容易嗎,確實不是,但是他們都遷移成功了。

          5.關(guān)于升級問題:

          我們同意,Vue3升級體驗并沒有想象中的那么流暢。Vue 將隨著吸取的經(jīng)驗不斷發(fā)展,我們絕對不打算在未來的Vue4中,進行這樣的破壞性重大升級。

          (We appreciate constructive feedback and agree that the Vue 3 upgrade experience isn't as smooth as it could be. Vue will keep evolving with the lessons learned, and we definitely do not plan to have disruptive major upgrades like this in the future.)

          6.關(guān)于這篇文章結(jié)論:

          在我看來,這篇文章整體上描繪的畫面比實際要黑暗(dark)得多,有不必要的夸張,在少數(shù)情況下是完全不正確的信息。我希望至少能糾正我在其他評論中指出的一些事實錯誤。

          七、總結(jié)討論:

          上述就是原作者提出來的問題以及尤大的回復,應該可以給各位正在考慮升級的小伙伴一點真實的參考意見。

          參考資料

          [1]

          https://medium.com/js-dojo/vue-3-was-a-mistake-that-we-should-not-repeat-81cc65484954: https://link.juejin.cn?target=https%3A%2F%2Fmedium.com%2Fjs-dojo%2Fvue-3-was-a-mistake-that-we-should-not-repeat-81cc65484954

          [2]

          https://v3-migration.vuejs.org/breaking-changes/events-api.html: https://link.juejin.cn?target=https%3A%2F%2Fv3-migration.vuejs.org%2Fbreaking-changes%2Fevents-api.html

          [3]

          https://dev.to/danielelkington/vue-s-darkest-day-3fgh: https://link.juejin.cn?target=https%3A%2F%2Fdev.to%2Fdanielelkington%2Fvue-s-darkest-day-3fgh

          [4]

          https://2021.stateofjs.com/en-US/libraries/front-end-frameworks/: https://link.juejin.cn?target=https%3A%2F%2F2021.stateofjs.com%2Fen-US%2Flibraries%2Ffront-end-frameworks%2F

          最后



          如果你覺得這篇內(nèi)容對你挺有啟發(fā),我想邀請你幫我個小忙:

          1. 點個「喜歡」或「在看」,讓更多的人也能看到這篇內(nèi)容

          2. 我組建了個氛圍非常好的前端群,里面有很多前端小伙伴,歡迎加我微信「sherlocked_93」拉你加群,一起交流和學習

          3. 關(guān)注公眾號「前端下午茶」,持續(xù)為你推送精選好文,也可以加我為好友,隨時聊騷。



          點個喜歡支持我吧,在看就更好了


          瀏覽 51
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

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

          手機掃一掃分享

          分享
          舉報
          <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>
                  五月天色欲 | 狼人综合久久网 | 99操B视频 | 日本一区二区电影久久精品 | 狠狠干2018 |