Vue 2

repository·main·Indexed Aug 11, 2026

https://github.com/vuejs/vue

A progressive JavaScript framework and reactive, component-oriented view layer for building user interfaces. Version 2.7.16 is currently at End of Life (EOL) and no longer maintained. The ecosystem includes vue-router, vuex, and vue-server-renderer for server-side rendering.

Tokens
47.6K
Snippets
183
Records
234
Agent score
91%

What's inside Vue

  1. Important: Vue 2 is End of Life

    main

    Vue 2 reached End of Life on December 31st, 2023. This repository is now inactive and no longer receives new features, updates, or security fixes.

    • New Projects: Use the latest version of Vue (3.x) available at vuejs/core.
    • Upgrading: Current Vue 2 users are strongly recommended to follow the v3 migration guide.
    • Legacy Support: If you must stay on Vue 2 but require security/compliance support, consider Vue 2 NES.
  2. What is Vue.js?

    main

    Vue (pronounced /vjuː/, like view) is a progressive framework for building user interfaces. It is designed to be incrementally adoptable, scaling from a simple library to a full framework.

    Core Characteristics

    • Approachable Core: A library focused on the view layer.
    • Ecosystem: A collection of supporting libraries to manage complexity in large Single-Page Applications (SPAs).
    • Browser Compatibility: Supports all ES5-compliant browsers (IE8 and below are not supported).
  3. Install vue-template-compiler

    main

    Use npm install vue-template-compiler to install the package. This package is used to pre-compile Vue 2.0 templates into render functions, which helps avoid runtime-compilation overhead and bypasses CSP restrictions.

    Note: In most cases, you should use vue-loader instead. You only need this package separately if you are building custom tools with specific requirements.

    npm install vue-template-compiler
  4. Run the Vue.js SSR benchmark

    main

    The SSR benchmark is designed for stress and regression testing. It renders a large table (1000 rows with 10 columns, totaling 10k components and ~30k elements) to compare the performance of renderToString against renderToStream.

    Note that results may vary based on system resources like available memory and processing power. The benchmark demonstrates that renderToStream provides performance benefits, such as faster time-to-first-byte and non-event-loop-blocking, by piping content through a stream.

    npm run bench:ssr
  5. Constraints on `<script>` and `<script setup>`

    main

    When using both <script> and <script setup> in a single SFC, the following rules apply:

    1. Language Consistency: The lang attribute must be the same for both blocks. For example, if <script setup> is lang="ts", the normal <script> must also be lang="ts" or lang="tsx".
    2. No ES Module Exports in <script setup>: You cannot use export statements inside a <script setup> block. If you need to export constants or named values, use a normal <script> block.
    3. Hoisting and Scope: Variables declared in <script setup> are hoisted outside the setup() function. Therefore, you cannot reference locally declared variables from <script setup> inside the normal <script> block's component options (like data, computed, or methods).
  6. Understand SSR Optimizability levels

    main

    The SSROptimizability type defines how much of a sub-tree can be optimized during SSR. This is used to determine if parts of the tree can be skipped or handled specially to improve performance.

    Values:

    • 0 (FALSE): Whole sub-tree is un-optimizable.
    • 1 (FULL): Whole sub-tree is optimizable.
    • 2 (SELF): The node itself is optimizable, but it contains un-optimizable children.
    • 3 (CHILDREN): The node itself is un-optimizable, but its children are fully optimizable.
    • 4 (PARTIAL): The node is un-optimizable and has some un-optimizable children.
  7. Implement Scoped Slots

    main

    A ScopedSlot is a function that receives data from the child component and returns content to be rendered. This allows child components to pass data back up to the slot consumer.

    In Vue 2.6+, scoped slots are expected to be normalized into an array of VNodes (NormalizedScopedSlot).

    Types:

    • ScopedSlot: A function returning VNode, string, boolean, number, null, undefined, or an array of these types.
    • NormalizedScopedSlot: A function that returns VNode[] | undefined.
    type ScopedSlot = (props: any) => ScopedSlotReturnValue
    type ScopedSlotReturnValue =
      | VNode
      | string
      | boolean
      | number
      | null
      | undefined
      | ScopedSlotReturnArray
    
    export type NormalizedScopedSlot = (props: any) => ScopedSlotChildren
    export type ScopedSlotChildren = VNode[] | undefined
  8. The `SFCDescriptor` structure

    main

    The SFCDescriptor is the primary output of the parsing process. It represents the entire structure of a .vue file.

    Key properties include:

    • source: The original raw source string.
    • filename: The filename (defaults to 'anonymous.vue').
    • template: An SFCBlock containing the template content, or null.
    • script: An SFCScriptBlock for standard <script> blocks, or null.
    • scriptSetup: An SFCScriptBlock for <script setup> blocks, or null.
    • styles: An array of SFCBlock objects for <style> blocks.
    • customBlocks: An array of SFCCustomBlock objects for non-standard tags.
    • cssVars: An array of CSS variable names extracted from the component.
    • errors: An array of string or WarningMessage objects representing parsing issues.
    • shouldForceReload: A function used for HMR (Hot Module Replacement) to determine if a reload is required based on import changes.