Vue 2 Documentation

website·Indexed 19 days ago

https://v2.cn.vuejs.org/v2/api/

Official documentation for Vue 2, including guides, API references, and a style guide. It features a cookbook with practical examples for form validation, client-side storage, and unit testing, as well as migration guides for transitioning from Vue 1.x, Vue Router 0.7.x, Vuex 0.6.x, and upgrading to Vue 2.7. The site also provides information on Long Term Support (LTS), End of Life (EOL), and various implementation examples such as TodoMVC and HackerNews clones.

Tokens
88.1K
Snippets
480
Records
645
Agent score
98%

What's inside Vue 2

  1. Overview of the Vue 2 Cookbook

    v2
    The Vue 2 Cookbook is a collection of specialized, deep-dive examples designed to help developers solve specific real-world problems. Unlike the general guides, which provide a sequential narrative of the framework, the Cookbook focuses on individual representative cases, explores complex examples in detail, explains necessary JavaScript (ES6+) features used in the solutions, and delves deeper into the Vue ecosystem (e.g., webpack, npm packages). It is intended for developers who already have a basic understanding of HTML, CSS, JavaScript, and npm/yarn.
  2. Overview of Vue 2 testing strategies

    v2

    Testing for Vue applications is divided into three main categories to ensure reliability during feature development, refactoring, and bug fixing:

    1. Unit Testing: Isolates and tests independent units of code to provide developer confidence in logic and stability.
    2. Component Testing: Tests Vue components by mounting them to a DOM (virtual or real) to assert behavior, often integrating with Vuex, Vue Router, and other plugins.
    3. End-to-End (E2E) Testing: Validates the entire application stack (frontend, backend services, and infrastructure) by simulating actual user interactions in a real-world environment.
  3. Introduction to Vue.js 2.x

    v2
    Vue.js is a progressive framework for building user interfaces. It is designed to be adopted incrementally, with its core library focusing on the view layer. It can be used as a simple library to enhance existing projects or combined with a modern toolchain to power complex single-page applications (SPAs).
  4. Overview of Vue 2.7 Backported Features

    v2

    Vue 2.7 is the final minor release of Vue 2 and backports several key features from Vue 3 to allow users to benefit from modern APIs without a full migration.

    Backported Features:

    • Composition API
    • <script setup> in Single File Components (SFCs)
    • CSS v-bind in SFCs
    • defineComponent() for improved type inference (replacing Vue.extend)
    • APIs: h(), useSlot(), useAttrs(), useCssModules()
    • Named exports for set(), del(), and nextTick() in ESM builds
    • emits option (for type checking only; does not affect runtime behavior)
    • ESNext syntax support in template expressions (processed via the same loader/plugin as .js files if using a build system).
  5. Introduction to Vue.js 2

    v2
    Vue.js is a progressive framework for building user interfaces. Unlike monolithic frameworks, Vue is designed to be adopted incrementally. Its core library focuses solely on the view layer, making it easy to integrate with third-party libraries or existing projects, while still being capable of powering complex single-page applications (SPAs) when combined with a modern toolchain and supporting libraries.
  6. Vue 2 End of Life (EOL) Status

    Vue 2 reached its official End of Life (EOL) on December 31, 2023. It no longer receives new features, updates, or bug fixes. However, it remains available through all existing distribution channels, including CDNs, package managers, and GitHub.
  7. Understand the purpose of the Vue Cookbook vs Guides

    v2

    The Vue Cookbook differs from the official Guides in four key areas:

    1. Focus: While Guides provide a sequential narrative, Cookbook recipes are standalone cases focusing on specific aspects of Vue.
    2. Depth: Cookbook recipes provide more complex, vivid examples and thorough explorations of a domain compared to the simplified examples in the Guides.
    3. JavaScript Instruction: The Cookbook explains necessary JavaScript features (including ES6+) required to implement the recipes, whereas Guides assume intermediate ES5 knowledge.
    4. Ecosystem Exploration: The Cookbook delves deeper into the libraries and tools commonly used by Vue developers (e.g., webpack) rather than assuming prior ecosystem knowledge.
  8. Develop native mobile apps with Vue

    v2

    Vue developers can build native iOS and Android applications using the following frameworks:

    1. Weex: A cross-platform UI framework (initiated by Alibaba) that allows using Vue syntax to develop native components.
    2. NativeScript-Vue: A plugin for NativeScript that enables building fully native apps using Vue.js.
  9. Understand Vue 2 Reactivity Tracking

    v2
    Vue 2 achieves reactivity by traversing all properties in the data object and converting them into getters and setters using Object.defineProperty. This allows Vue to track dependencies and notify watchers when a property is accessed or modified, triggering a component re-render. Because Object.defineProperty is an ES5 feature that cannot be shimmed, Vue 2 does not support IE8 or lower.
  10. Get help and support for Vue.js

    v2

    Developers can access support and community interaction through the following official channels:

    • Forum: The primary location for asking questions about Vue and its ecosystem.
    • Chat Room: A real-time environment for developers to connect and communicate.
    • Meetups: Local gatherings for Vue enthusiasts and aspiring community leaders.
    • GitHub: Used for reporting bugs, requesting new features via issues, and submitting pull requests.
  11. Vue 2 End of Life (EOL) status

    Vue 2 reached its official End of Life (EOL) on December 31, 2023. It no longer receives new features, updates, or bug fixes. However, it remains available through all existing distribution channels, including CDNs, package managers, and GitHub.
  12. Use the 'is' attribute to bypass DOM template restrictions

    v2

    Certain HTML elements (like <ul>, <ol>, <table>, and <select>) have strict rules about which child elements they can contain. If a custom component is placed directly inside these elements in a DOM template, it may be treated as invalid content and hoisted outside the element, causing rendering errors. To fix this, use the is attribute on a valid child element (e.g., using <tr> inside a <table>) to tell Vue to render the custom component in that position.

    Note: This restriction does not apply when using templates from strings, Single File Components (.vue files), or <script type="text/x-template"> blocks.

    <!-- Incorrect: <blog-post-row> may be hoisted out of <table> -->
    <table>
      <blog-post-row></blog-post-row>
    </table>
    
    <!-- Correct: Use the 'is' attribute on a valid <tr> element -->
    <table>
      <tr is="blog-post-row"></tr>
    </table>