← Back to Vue.js Course | Chapter 10: Best Practices | Lesson 6 of 6

Vue 3 बनाम Vue 2 के अंतर

Vue 3 Composition API, faster rendering, और Vue 2 से कई breaking changes लाया।

Vue 3 बनाम Vue 2 Differences

Vue 3 new Vue की बजाय createApp इस्तेमाल करता है, multiple root nodes support करता है, event bus methods की जगह लेता है, destroy hooks का नाम बदलकर unmount करता है, modelValue के साथ v-model इस्तेमाल करता है, और Teleport, Suspense, और Composition API introduce करता है।

यह TypeScript में एक Proxy-based reactivity system के साथ फिर से लिखा गया है।

Note: Vue 2 December 2023 में end of life पर पहुँच गया।

उदाहरण: Vue 3 vs Vue 2 differences

markup
<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
</head>
<body>
<div id="app">
  <p>Vue 3 API: createApp is a {{ createAppType }}, major version {{ major }}</p>
  <fragment-demo></fragment-demo>
</div>
<script>
  const app = Vue.createApp({ data() { return { createAppType: typeof Vue.createApp, major: Vue.version.split(".")[0] }; } });
  // Vue 3 components may have several root nodes (fragments)
  app.component("fragment-demo", { template: "<h4>Root one</h4><h4>Root two</h4>" });
  app.mount("#app");
</script>
</body>
</html>

<!-- Output:
Rendered: Vue 3 API: createApp is a function, major version 3Root oneRoot two
-->
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. Vue 3 में new Vue इस्तेमाल करना
  2. $on और $off इस्तेमाल करना
  3. Vue 2 के filters feature इस्तेमाल करना
चैप्टर सारांश
  • createApp new Vue की जगह लेता है
  • Multiple root elements allowed हैं
  • Hooks का नाम बदलकर unmount हुआ
  • Composition API, Teleport, Suspense जैसी नई चीज़ें आईं
🔒

Chapter Quiz — Complete all 6 topics to unlock

0/6 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.