项目介绍

Vue(发音为 /vjuː/,类似于 view)是一款渐进式 JavaScript 框架,专门用于构建用户界面。它由华人开发者尤雨溪(Evan You)于 2014 年创建,在全球前端开发领域享有极高声誉。

Vue 从设计之初就考虑了渐进式采用的理念,核心库只关注视图层,易于上手,同时能通过配套的生态系统库轻松扩展为功能强大的前端框架,适应各种规模的应用开发需求。

项目信息 详情
GitHub 星标210,036+
创建者尤雨溪 (Evan You)
编程语言JavaScript / TypeScript
当前状态Vue 2 已于 2023年12月31日 停止维护(EOL)
最新版本Vue 3(活跃开发中,仓库:vuejs/core)
开源许可MIT License
官方网站vuejs.org

注意:Vue 2 已于 2023 年 12 月 31 日到达生命周期终点(End of Life),不再接收新功能、更新或修复。新项目请使用 Vue 3

主要特点

易于上手

如果你熟悉 HTML、CSS 和 JavaScript,就能快速上手 Vue。清晰的文档和低学习曲线让初学者也能迅速构建应用。

灵活多变

Vue 的生态系统可以在库和完整框架之间灵活扩展,适应不同规模的项目需求,从简单的页面增强到复杂的单页应用。

高性能

优化的虚拟 DOM 实现和智能的组件重渲染机制,确保了出色的运行时性能,让应用始终保持流畅。

虚拟 DOM

使用虚拟 DOM 技术,高效计算最小变更量,减少实际 DOM 操作,大幅提升渲染性能。

响应式数据绑定

Vue 的响应式系统自动追踪数据依赖,当数据变化时精确更新相关视图,简化了状态管理。

组件化架构

基于组件的开发模式,支持单文件组件(.vue 文件),将模板、逻辑和样式封装在一起,提高代码可维护性。

核心优势

  • 渐进式采用 - 可以从一个简单的脚本标签开始,逐步升级为完整的前端工程化方案
  • 丰富的生态系统 - Vue Router、Vuex/Pinia、Vue CLI/Vite 等官方工具形成完整工具链
  • 活跃的中文社区 - 作为华人创建的框架,拥有大量中文文档和社区资源
  • 服务端渲染 - 通过 Nuxt.js 或内置 SSR 支持,轻松实现服务端渲染
  • TypeScript 支持 - Vue 3 使用 TypeScript 重写,提供一流的类型支持
  • 开发者工具 - 官方浏览器 DevTools 扩展,提供便捷的调试体验

生态系统

Vue 拥有完善的官方生态系统,为不同的开发需求提供了专业的解决方案:

项目 说明 用途
Vue Router 官方路由管理器 单页应用路由导航
Vuex 状态管理模式 大规模应用的集中式状态管理
Vue CLI 脚手架工具 快速创建和配置 Vue 项目
Vue Loader Webpack 加载器 支持单文件组件(.vue)的编译
Vue Server Renderer 服务端渲染 实现 SSR 以提升 SEO 和首屏性能
Vue DevTools 浏览器开发工具 调试组件树、状态和事件
Vue Class Component 类风格 API 基于 TypeScript 装饰器的类式组件
Vue RX RxJS 集成 在 Vue 中使用响应式流编程

快速开始

使用 CDN 引入(最简单)

<!-- 开发版本,包含警告信息 --> <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script> <!-- 生产版本,优化了文件大小和速度 --> <script src="https://cdn.jsdelivr.net/npm/vue@2"></script>

使用 npm 安装

# 安装 Vue 2 npm install vue@2 # 或使用 Vue CLI 创建新项目(推荐 Vue 3) npm install -g @vue/cli vue create my-project

Hello World 示例

<div id="app"> {{ message }} </div> <script> var app = new Vue({ el: '#app', data: { message: '你好,Vue!' } }) </script>

Vue 3 迁移建议

如果你正在开始新项目,强烈建议使用 Vue 3。Vue 3 带来了 Composition API、更好的 TypeScript 支持和显著的性能提升。迁移指南请参考 官方迁移文档

Vue 2 与 Vue 3 对比

特性 Vue 2 Vue 3
维护状态 已停止维护(EOL) 活跃开发中
API 风格 Options API Options API + Composition API
TypeScript 基本支持 一流支持(使用 TS 重写)
性能 良好 更优(Tree-shaking、更快的虚拟DOM)
包体积 较大 更小(支持 Tree-shaking)
推荐构建工具 Vue CLI + Webpack Vite(官方推荐)
状态管理 Vuex Pinia(官方推荐)

社区议题

以下是该项目当前开放的 Issue(按评论数排序),共 159 条,标题已翻译为中文供参考。

编号 议题标题(中文翻译 / 英文原文) 创建日期 评论
#7186 Establish a standard way to document 组件 and its props
Establish a standard way to document component and its props
讨论
2017-12-05 69
#8721 Property 'xxx' does not exist on type CombinedVueInstance ?
Property 'xxx' does not exist on type CombinedVueInstance ?
typescript
2018-08-28 56
#3842 $refs 应该 be reactive to be able to use them in computed properties
$refs should be reactive to be able to use them in computed properties
功能请求讨论
2016-10-03 52
#6351 更新 slot content without rerendering rest of 组件
Update slot content without rerendering rest of component
improvement
2017-08-11 33
#8996 允许 2018-10-26 32
#6487 Provide/inject for 自定义 directives
Provide/inject for custom directives
功能请求
2017-08-31 32
#10366 Click Event Triggers on Complex Buttons are ignored in some environments
Click Event Triggers on Complex Buttons are ignored in some environments
contribution welcomebrowser quirkshas PR
2019-08-07 31
#9847 [template-renderer] Make it possible to not automatically 渲染 used async scripts
[template-renderer] Make it possible to not automatically render used async scripts
功能请求
2019-04-08 26
#10252 Wrong definition of the type AsyncComponentFactory
Wrong definition of the type AsyncComponentFactory
适合新手typescripthas PR
2019-07-10 24
#7492 Functional single 文件 组件 with 组件 option.
Functional single file component with components option.
功能请求improvementhas PR
2018-01-21 23
#11023 Generate distinct paths for 支持 .vue 文件 in sourcemaps
Generate distinct paths for supporting .vue files in sourcemaps
讨论improvement
2020-01-17 22
#7830 v-model 支持 for web 组件 (stenciljs)
v-model support for web components (stenciljs)
功能请求
2018-03-14 21
#11122 Trailing whitespaces are trimmed from the end of inline element when 页面 is being parsed by Vue
Trailing whitespaces are trimmed from the end of inline element when page is being parsed by Vue
2020-02-18 20
#9467 自定义 错误 message from prop validator
Custom error message from prop validator
功能请求
2019-02-10 20
#9325 Modifier to propagate/forward events to parent
Modifier to propagate/forward events to parent
功能请求
2019-01-15 20
#9357 Function-type props 损坏 in TypeScript
Function-type props broken in TypeScript
typescript
2019-01-22 18
#8025 Creating a 组件 named map 应该 warn the user (as with button)
Creating a component named map should warn the user (as with button)
contribution welcomeimprovement适合新手has PR
2018-04-14 17
#7943 Provide a way to define different name for prop attribute
Provide a way to define different name for prop attribute
功能请求
2018-04-01 17
#6929 rerenders while 变更 affects only sibling elements
rerenders while changes affects only sibling elements
缺陷has workaround
2017-10-26 17
#7846 Extending object syntax of v-on to 支持 modifiers
Extending object syntax of v-on to support modifiers
功能请求
2018-03-16 16
#5837 Provided props are not injected into functional 组件
Provided props are not injected into functional components
缺陷
2017-06-07 16
#12829 需要 a lifecycle hook which 可以 exec when a 组件 be going to destroy, and it happens before next 组件 创建
need a lifecycle hook which could exec when a component be going to destroy, and it happens before next component created
2022-10-14 15
#12651 如何 better cooperate with Vuex and Vue Router in in 2.7
How to better cooperate with Vuex and Vue Router in in 2.7
2.7docs
2022-07-12 15
#10547 Infinite loop in vue-template-compiler
Infinite loop in vue-template-compiler
缺陷contribution welcomehas PR
2019-09-22 15
#10191 Warn if colon shorthand is used on v-if/v-html/etc.
Warn if colon shorthand is used on v-if/v-html/etc.
contribution welcome功能请求适合新手has PRwarnings
2019-06-25 15
#8409 Computed Watchers Not Firing
Computed Watchers Not Firing
browser quirks需要帮助
2018-06-25 15
#8129 warn if $set is used on a property that already exist
warn if $set is used on a property that already exist
功能请求适合新手has PR
2018-05-04 15
#7595 SSR 组件 Cache doesn't cache Strings
SSR Component Cache doesn't cache Strings
improvement
2018-02-02 15
#7136 Issues with v-model.number
Issues with v-model.number
讨论
2017-11-27 15
#8516 错误 thrown when using transition-group with conditionally 渲染 children
Error thrown when using transition-group with conditionally rendered children
transition
2018-07-18 13
#8278 Make vue available to other libraries without having to import it
Make vue available to other libraries without having to import it
讨论
2018-05-30 13
#7984 添加 `options` property to the 渲染 context of functional 组件
add `options` property to the render context of functional component
功能请求
2018-04-08 13
#7720 Vue warns about 缺失 required prop that has a 默认 value
Vue warns about missing required prop that has a default value
讨论improvement
2018-02-28 13
#6872 Asset 支持 for functional 组件
Asset support for functional components
intend to implement功能请求improvementhas PR
2017-10-21 13
#4991