├── src
├── CNAME
├── index.md
├── images
│ ├── hn.png
│ ├── data.png
│ ├── mvvm.png
│ ├── state.png
│ ├── components.png
│ ├── lifecycle.png
│ ├── props-events.png
│ ├── vue-component.png
│ ├── hn-architecture.png
│ └── vue-component-with-preprocessors.png
├── v2
│ ├── examples
│ │ ├── elastic-header.md
│ │ ├── index.md
│ │ ├── grid-component.md
│ │ ├── tree-view.md
│ │ ├── svg.md
│ │ ├── modal.md
│ │ ├── select2.md
│ │ ├── commits.md
│ │ ├── firebase.md
│ │ ├── todomvc.md
│ │ └── hackernews.md
│ ├── guide
│ │ ├── ssr.md
│ │ ├── routing.md
│ │ ├── deployment.md
│ │ ├── plugins.md
│ │ ├── join.md
│ │ ├── state-management.md
│ │ ├── migration-vuex.md
│ │ ├── instance.md
│ │ ├── single-file-components.md
│ │ ├── mixins.md
│ │ ├── unit-testing.md
│ │ ├── installation.md
│ │ ├── reactivity.md
│ │ ├── class-and-style.md
│ │ ├── custom-directive.md
│ │ ├── syntax.md
│ │ ├── conditional.md
│ │ └── events.md
│ └── cookbook
│ │ ├── index.md
│ │ └── adding-instance-properties.md
├── _posts
│ ├── vue-011-release.md
│ ├── vue-next.md
│ ├── 011-component.md
│ ├── why-no-template-url.md
│ ├── vue-cli.md
│ ├── common-gotchas.md
│ ├── 1.0.0-release.md
│ ├── vuejs-010-release.md
│ ├── march-update.md
│ ├── announcing-2.0.md
│ └── 012-release.md
├── about
│ ├── guide.md
│ └── index.md
└── support-vuejs
│ └── index.md
├── themes
└── vue
│ ├── layout
│ ├── partials
│ │ ├── ad.ejs
│ │ ├── ga.ejs
│ │ ├── header.ejs
│ │ ├── community_dropdown.ejs
│ │ ├── language_dropdown.ejs
│ │ ├── main_menu.ejs
│ │ ├── ecosystem_dropdown.ejs
│ │ ├── sponsors.ejs
│ │ ├── sidebar.ejs
│ │ └── contributors.ejs
│ ├── post.ejs
│ ├── page.ejs
│ ├── index.ejs
│ └── layout.ejs
│ ├── source
│ ├── images
│ │ ├── down.png
│ │ ├── feed.png
│ │ ├── logo.png
│ │ ├── menu.png
│ │ ├── tde.png
│ │ ├── 2mhost.png
│ │ ├── check.png
│ │ ├── icons.png
│ │ ├── juejin.png
│ │ ├── paypal.png
│ │ ├── search.png
│ │ ├── stdlib.png
│ │ ├── actualize.png
│ │ ├── chaitin.png
│ │ ├── fancygrid.png
│ │ ├── itunescn.png
│ │ ├── jsfiddle.png
│ │ ├── laravel.png
│ │ ├── monterail.png
│ │ ├── patreon.png
│ │ ├── someline.png
│ │ ├── tmvuejs2.png
│ │ ├── trisoft.png
│ │ ├── vuejobs.png
│ │ ├── deepstream.png
│ │ ├── famebroker.png
│ │ ├── htmlburger.png
│ │ ├── strikingly.png
│ │ ├── transition.png
│ │ ├── upyun-large.png
│ │ ├── upyun-main.jpg
│ │ ├── upyun-small.png
│ │ ├── component_io.png
│ │ ├── upyun-main-2.jpg
│ │ ├── upyun-main-3.jpg
│ │ └── vuejobs.svg
│ ├── fonts
│ │ ├── Roboto_Mono
│ │ │ └── RobotoMono-Regular.ttf
│ │ └── Source_Sans_Pro
│ │ │ ├── SourceSansPro-Light.ttf
│ │ │ ├── SourceSansPro-Regular.ttf
│ │ │ ├── SourceSansPro-Semibold.ttf
│ │ │ └── OFL.txt
│ ├── css
│ │ ├── _sponsor.styl
│ │ ├── _migration.styl
│ │ ├── _fonts.styl
│ │ ├── benchmark.styl
│ │ ├── _settings.styl
│ │ ├── search.styl
│ │ ├── _syntax.styl
│ │ ├── _demo.styl
│ │ ├── _header.styl
│ │ ├── _sidebar.styl
│ │ ├── index.styl
│ │ ├── _common.styl
│ │ └── page.styl
│ └── js
│ │ └── smooth-scroll.min.js
│ └── _config.yml
├── assets
├── logo.ai
├── state.ai
├── icons.psd
└── lifecycle.ai
├── README.md
├── .gitignore
├── Makefile
├── server.js
├── package.json
├── LICENSE
├── update.js
└── _config.yml
/src/CNAME:
--------------------------------------------------------------------------------
1 | cn.vuejs.org
--------------------------------------------------------------------------------
/themes/vue/layout/partials/ad.ejs:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/themes/vue/layout/partials/ga.ejs:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/src/index.md:
--------------------------------------------------------------------------------
1 | index: true
2 | ---
3 |
--------------------------------------------------------------------------------
/assets/logo.ai:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/IFmiss/cn.vuejs.org/master/assets/logo.ai
--------------------------------------------------------------------------------
/assets/state.ai:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/IFmiss/cn.vuejs.org/master/assets/state.ai
--------------------------------------------------------------------------------
/assets/icons.psd:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/IFmiss/cn.vuejs.org/master/assets/icons.psd
--------------------------------------------------------------------------------
/src/images/hn.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/IFmiss/cn.vuejs.org/master/src/images/hn.png
--------------------------------------------------------------------------------
/assets/lifecycle.ai:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/IFmiss/cn.vuejs.org/master/assets/lifecycle.ai
--------------------------------------------------------------------------------
/src/images/data.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/IFmiss/cn.vuejs.org/master/src/images/data.png
--------------------------------------------------------------------------------
/src/images/mvvm.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/IFmiss/cn.vuejs.org/master/src/images/mvvm.png
--------------------------------------------------------------------------------
/src/images/state.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/IFmiss/cn.vuejs.org/master/src/images/state.png
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ## vue.js 2.0 中文文档 https://cn.vuejs.org
2 |
3 | > 欢迎大家一起参与校对工作
4 |
5 | ### 感谢所有参与翻译的朋友们!
--------------------------------------------------------------------------------
/src/images/components.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/IFmiss/cn.vuejs.org/master/src/images/components.png
--------------------------------------------------------------------------------
/src/images/lifecycle.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/IFmiss/cn.vuejs.org/master/src/images/lifecycle.png
--------------------------------------------------------------------------------
/src/images/props-events.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/IFmiss/cn.vuejs.org/master/src/images/props-events.png
--------------------------------------------------------------------------------
/src/images/vue-component.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/IFmiss/cn.vuejs.org/master/src/images/vue-component.png
--------------------------------------------------------------------------------
/src/images/hn-architecture.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/IFmiss/cn.vuejs.org/master/src/images/hn-architecture.png
--------------------------------------------------------------------------------
/themes/vue/source/images/down.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/IFmiss/cn.vuejs.org/master/themes/vue/source/images/down.png
--------------------------------------------------------------------------------
/themes/vue/source/images/feed.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/IFmiss/cn.vuejs.org/master/themes/vue/source/images/feed.png
--------------------------------------------------------------------------------
/themes/vue/source/images/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/IFmiss/cn.vuejs.org/master/themes/vue/source/images/logo.png
--------------------------------------------------------------------------------
/themes/vue/source/images/menu.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/IFmiss/cn.vuejs.org/master/themes/vue/source/images/menu.png
--------------------------------------------------------------------------------
/themes/vue/source/images/tde.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/IFmiss/cn.vuejs.org/master/themes/vue/source/images/tde.png
--------------------------------------------------------------------------------
/themes/vue/source/images/2mhost.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/IFmiss/cn.vuejs.org/master/themes/vue/source/images/2mhost.png
--------------------------------------------------------------------------------
/themes/vue/source/images/check.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/IFmiss/cn.vuejs.org/master/themes/vue/source/images/check.png
--------------------------------------------------------------------------------
/themes/vue/source/images/icons.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/IFmiss/cn.vuejs.org/master/themes/vue/source/images/icons.png
--------------------------------------------------------------------------------
/themes/vue/source/images/juejin.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/IFmiss/cn.vuejs.org/master/themes/vue/source/images/juejin.png
--------------------------------------------------------------------------------
/themes/vue/source/images/paypal.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/IFmiss/cn.vuejs.org/master/themes/vue/source/images/paypal.png
--------------------------------------------------------------------------------
/themes/vue/source/images/search.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/IFmiss/cn.vuejs.org/master/themes/vue/source/images/search.png
--------------------------------------------------------------------------------
/themes/vue/source/images/stdlib.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/IFmiss/cn.vuejs.org/master/themes/vue/source/images/stdlib.png
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | Thumbs.db
3 | db.json
4 | *.log
5 | node_modules/
6 | public/
7 | .deploy*/
8 | src/_drafts
9 | .avoscloud/
--------------------------------------------------------------------------------
/themes/vue/source/images/actualize.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/IFmiss/cn.vuejs.org/master/themes/vue/source/images/actualize.png
--------------------------------------------------------------------------------
/themes/vue/source/images/chaitin.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/IFmiss/cn.vuejs.org/master/themes/vue/source/images/chaitin.png
--------------------------------------------------------------------------------
/themes/vue/source/images/fancygrid.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/IFmiss/cn.vuejs.org/master/themes/vue/source/images/fancygrid.png
--------------------------------------------------------------------------------
/themes/vue/source/images/itunescn.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/IFmiss/cn.vuejs.org/master/themes/vue/source/images/itunescn.png
--------------------------------------------------------------------------------
/themes/vue/source/images/jsfiddle.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/IFmiss/cn.vuejs.org/master/themes/vue/source/images/jsfiddle.png
--------------------------------------------------------------------------------
/themes/vue/source/images/laravel.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/IFmiss/cn.vuejs.org/master/themes/vue/source/images/laravel.png
--------------------------------------------------------------------------------
/themes/vue/source/images/monterail.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/IFmiss/cn.vuejs.org/master/themes/vue/source/images/monterail.png
--------------------------------------------------------------------------------
/themes/vue/source/images/patreon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/IFmiss/cn.vuejs.org/master/themes/vue/source/images/patreon.png
--------------------------------------------------------------------------------
/themes/vue/source/images/someline.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/IFmiss/cn.vuejs.org/master/themes/vue/source/images/someline.png
--------------------------------------------------------------------------------
/themes/vue/source/images/tmvuejs2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/IFmiss/cn.vuejs.org/master/themes/vue/source/images/tmvuejs2.png
--------------------------------------------------------------------------------
/themes/vue/source/images/trisoft.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/IFmiss/cn.vuejs.org/master/themes/vue/source/images/trisoft.png
--------------------------------------------------------------------------------
/themes/vue/source/images/vuejobs.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/IFmiss/cn.vuejs.org/master/themes/vue/source/images/vuejobs.png
--------------------------------------------------------------------------------
/themes/vue/source/images/deepstream.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/IFmiss/cn.vuejs.org/master/themes/vue/source/images/deepstream.png
--------------------------------------------------------------------------------
/themes/vue/source/images/famebroker.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/IFmiss/cn.vuejs.org/master/themes/vue/source/images/famebroker.png
--------------------------------------------------------------------------------
/themes/vue/source/images/htmlburger.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/IFmiss/cn.vuejs.org/master/themes/vue/source/images/htmlburger.png
--------------------------------------------------------------------------------
/themes/vue/source/images/strikingly.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/IFmiss/cn.vuejs.org/master/themes/vue/source/images/strikingly.png
--------------------------------------------------------------------------------
/themes/vue/source/images/transition.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/IFmiss/cn.vuejs.org/master/themes/vue/source/images/transition.png
--------------------------------------------------------------------------------
/themes/vue/source/images/upyun-large.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/IFmiss/cn.vuejs.org/master/themes/vue/source/images/upyun-large.png
--------------------------------------------------------------------------------
/themes/vue/source/images/upyun-main.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/IFmiss/cn.vuejs.org/master/themes/vue/source/images/upyun-main.jpg
--------------------------------------------------------------------------------
/themes/vue/source/images/upyun-small.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/IFmiss/cn.vuejs.org/master/themes/vue/source/images/upyun-small.png
--------------------------------------------------------------------------------
/themes/vue/source/images/component_io.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/IFmiss/cn.vuejs.org/master/themes/vue/source/images/component_io.png
--------------------------------------------------------------------------------
/themes/vue/source/images/upyun-main-2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/IFmiss/cn.vuejs.org/master/themes/vue/source/images/upyun-main-2.jpg
--------------------------------------------------------------------------------
/themes/vue/source/images/upyun-main-3.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/IFmiss/cn.vuejs.org/master/themes/vue/source/images/upyun-main-3.jpg
--------------------------------------------------------------------------------
/src/images/vue-component-with-preprocessors.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/IFmiss/cn.vuejs.org/master/src/images/vue-component-with-preprocessors.png
--------------------------------------------------------------------------------
/themes/vue/source/fonts/Roboto_Mono/RobotoMono-Regular.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/IFmiss/cn.vuejs.org/master/themes/vue/source/fonts/Roboto_Mono/RobotoMono-Regular.ttf
--------------------------------------------------------------------------------
/themes/vue/source/css/_sponsor.styl:
--------------------------------------------------------------------------------
1 | .sponsors-page
2 | a, img
3 | width 120px
4 | display inline-block
5 | vertical-align middle
6 | a
7 | margin 10px 20px
8 |
--------------------------------------------------------------------------------
/themes/vue/source/fonts/Source_Sans_Pro/SourceSansPro-Light.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/IFmiss/cn.vuejs.org/master/themes/vue/source/fonts/Source_Sans_Pro/SourceSansPro-Light.ttf
--------------------------------------------------------------------------------
/themes/vue/source/fonts/Source_Sans_Pro/SourceSansPro-Regular.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/IFmiss/cn.vuejs.org/master/themes/vue/source/fonts/Source_Sans_Pro/SourceSansPro-Regular.ttf
--------------------------------------------------------------------------------
/themes/vue/source/fonts/Source_Sans_Pro/SourceSansPro-Semibold.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/IFmiss/cn.vuejs.org/master/themes/vue/source/fonts/Source_Sans_Pro/SourceSansPro-Semibold.ttf
--------------------------------------------------------------------------------
/themes/vue/_config.yml:
--------------------------------------------------------------------------------
1 | site_description: "Vue.js - Intuitive, Fast and Composable MVVM for building interactive interfaces."
2 | google_analytics: UA-46852172-1
3 | root_domain: cn.vuejs.org
4 | vue_version: 2.1.4
--------------------------------------------------------------------------------
/src/v2/examples/elastic-header.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: 具有伸缩性的 Header
3 | type: examples
4 | order: 7
5 | ---
6 |
7 |
8 |
--------------------------------------------------------------------------------
/themes/vue/layout/partials/header.ejs:
--------------------------------------------------------------------------------
1 |
10 |
--------------------------------------------------------------------------------
/src/v2/examples/index.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Markdown 编辑器
3 | type: examples
4 | order: 0
5 | ---
6 |
7 | > 蠢萌的 Markdown 编辑器。
8 |
9 |
10 |
--------------------------------------------------------------------------------
/src/v2/examples/grid-component.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: 网格组件
3 | type: examples
4 | order: 3
5 | ---
6 |
7 | > 本示例创建了一个可复用组件,可结合外部数据来使用它。
8 |
9 |
10 |
--------------------------------------------------------------------------------
/src/v2/examples/tree-view.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: 树形视图
3 | type: examples
4 | order: 4
5 | ---
6 |
7 | > 本示例是一个简单的树形视图实现,它展现了组件的递归使用。
8 |
9 |
10 |
--------------------------------------------------------------------------------
/src/v2/examples/svg.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: SVG 图表
3 | type: examples
4 | order: 5
5 | ---
6 |
7 | > 本示例展示了一个结合体,它由常用组件、计算属性、2 种绑定方式和 SVG 的支持组成。
8 |
9 |
10 |
--------------------------------------------------------------------------------
/src/v2/examples/modal.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: 模式组件
3 | type: examples
4 | order: 6
5 | ---
6 |
7 | > 使用到的特性:组件,prop 传递,内容插入(content insertion),过渡(transitions)。
8 |
9 |
10 |
--------------------------------------------------------------------------------
/src/v2/examples/select2.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: 内嵌组件
3 | type: examples
4 | order: 8
5 | ---
6 |
7 | > 在本例中,我们整合了第三方 jQuery 插件(select2),怎么做到的呢?就是把它内嵌在一个常用组件中==
8 |
9 |
10 |
--------------------------------------------------------------------------------
/src/v2/examples/commits.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: GitHub 提交
3 | type: examples
4 | order: 1
5 | ---
6 |
7 | > 这个例子从 Github 的 API 中获取了最新的 Vue.js 提交数据,并且以列表形式将它们展示了出来。你可以轻松地切换 master 和 dev 分支。
8 |
9 |
10 |
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | all: update deploy
2 |
3 | deploy:
4 | rm -rf public db.json
5 | hexo generate
6 | hexo deploy
7 |
8 | update:
9 | cd ../vue && \
10 | git checkout -- dist && \
11 | git checkout dev && \
12 | npm run build
13 | cp ../vue/dist/vue.min.js themes/vue/source/js/vue.min.js
14 | cp ../vue/dist/vue.js themes/vue/source/js/vue.js
15 | node update.js
16 |
--------------------------------------------------------------------------------
/src/v2/examples/firebase.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Firebase + 验证
3 | type: examples
4 | order: 2
5 | ---
6 |
7 | > 本示例使用 [Firebase](https://firebase.google.com/) 作为数据存储后端,同时在客户端进行数据实时同步(你可以在多个浏览器窗口去打开它来验证)。另外,它通过计算属性实时验证,并且添加/移除选项时触发 CSS 过渡。
8 |
9 |
--------------------------------------------------------------------------------
/themes/vue/source/css/_migration.styl:
--------------------------------------------------------------------------------
1 | .content.guide[class*="migration"]
2 | h2, h3
3 | > sup
4 | margin-left: .3em
5 | color: #b9465c
6 | .upgrade-path
7 | padding: 2em
8 | background: rgba(73, 195, 140, .1)
9 | border-radius: 2px
10 | > h4
11 | margin-top: 0
12 | > p:last-child
13 | margin-bottom: 0
14 |
15 |
--------------------------------------------------------------------------------
/src/v2/guide/ssr.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: 服务端渲染
3 | type: guide
4 | order: 24
5 | ---
6 |
7 | ## SSR 完全指南
8 |
9 | 在 2.3 发布后我们发布了一份完整的构建 Vue 服务端渲染应用的指南。这份指南非常深入,适合已经熟悉 Vue, webpack 和 Node.js 开发的开发者阅读。请移步 [ssr.vuejs.org](https://ssr.vuejs.org)。(目前只有英文版,社区正在进行中文版的翻译)
10 |
11 | ## Nuxt.js
12 |
13 | 从头搭建一个服务端渲染的应用是相当复杂的。幸运的是,我们有一个优秀的社区项目 [Nuxt.js](https://nuxtjs.org/) 让这一切变得非常简单。Nuxt 是一个基于 Vue 生态的更高层的框架,为开发服务端渲染的 Vue 应用提供了极其便利的开发体验。更酷的是,你甚至可以用它来做为静态站生成器。推荐尝试。
14 |
15 | ***
16 |
17 | > 原文: http://vuejs.org/guide/ssr.html
18 |
19 | ***
20 |
--------------------------------------------------------------------------------
/src/v2/examples/todomvc.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: TodoMVC
3 | type: examples
4 | order: 9
5 | ---
6 |
7 | > 本例是一个完全和规范一致的 TodoMVC 实现,只用了 120 行有效的 JavaScript(不包含注释和空行)。
8 |
9 | Note that if your web browser is configured to block 3rd-party data/cookies, the example below will not work, as the `localStorage` data will fail to be saved from JSFiddle. You'll have to click on `Edit in JSFiddle` to see the live result.
10 |
11 |
12 |
--------------------------------------------------------------------------------
/server.js:
--------------------------------------------------------------------------------
1 | var express = require('express');
2 | var AV = require('leanengine');
3 | var path = require('path');
4 | var app = express();
5 |
6 | var port = process.env.LEANCLOUD_APP_PORT || 3000;
7 |
8 | AV.init({
9 | appId: process.env.LEANCLOUD_APP_ID,
10 | appKey: process.env.LEANCLOUD_APP_KEY,
11 | masterKey: process.env.LEANCLOUD_APP_MASTER_KEY
12 | });
13 | app.enable('trust proxy');
14 | app.use(AV.express());
15 | app.use(AV.Cloud.HttpsRedirect());
16 | app.use(express.static(__dirname + '/public'));
17 | app.get('/', function(req, res) {
18 | res.sendFile(path.resolve('./public/index.html'))
19 | });
20 |
21 | app.listen(port);
--------------------------------------------------------------------------------
/themes/vue/layout/partials/community_dropdown.ejs:
--------------------------------------------------------------------------------
1 |
2 | 社区
3 |
10 |
11 |
--------------------------------------------------------------------------------
/themes/vue/source/css/_fonts.styl:
--------------------------------------------------------------------------------
1 | @font-face
2 | font-family "Source Sans Pro"
3 | src local("Source Sans Pro"),
4 | url(/fonts/Source_Sans_Pro/SourceSansPro-Regular.ttf)
5 |
6 | @font-face
7 | font-family "Source Sans Pro"
8 | src local("Source Sans Pro Light"),
9 | url(/fonts/Source_Sans_Pro/SourceSansPro-Light.ttf)
10 | font-weight 300
11 |
12 | @font-face
13 | font-family "Source Sans Pro"
14 | src local("Source Sans Pro Semibold"),
15 | url(/fonts/Source_Sans_Pro/SourceSansPro-Semibold.ttf)
16 | font-weight 600
17 |
18 | @font-face
19 | font-family "Roboto Mono"
20 | src local("Roboto Mono"),
21 | url(/fonts/Roboto_Mono/RobotoMono-Regular.ttf)
22 |
--------------------------------------------------------------------------------
/themes/vue/layout/partials/language_dropdown.ejs:
--------------------------------------------------------------------------------
1 |
2 | 多语言
3 |
11 |
12 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "cn.vuejs.org",
3 | "version": "1.0.18",
4 | "private": true,
5 | "hexo": {
6 | "version": "3.2.2"
7 | },
8 | "dependencies": {
9 | "hexo": "^3.2.2",
10 | "hexo-browsersync": "^0.2.0",
11 | "hexo-deployer-git": "0.2.0",
12 | "hexo-generator-alias": "git+https://github.com/chrisvfritz/vuejs.org-hexo-generator-alias.git",
13 | "hexo-generator-archive": "^0.1.4",
14 | "hexo-generator-category": "^0.1.3",
15 | "hexo-generator-feed": "^1.1.0",
16 | "hexo-generator-index": "^0.2.0",
17 | "hexo-generator-tag": "^0.2.0",
18 | "hexo-renderer-ejs": "^0.2.0",
19 | "hexo-renderer-marked": "^0.2.10",
20 | "hexo-renderer-stylus": "^0.3.1",
21 | "hexo-server": "^0.2.0"
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/themes/vue/layout/partials/main_menu.ejs:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | 教程
7 | API
8 | 示例
9 | 参与贡献
10 | <%- partial('partials/community_dropdown') %>
11 | <%- partial('partials/ecosystem_dropdown') %>
12 | <%- partial('partials/language_dropdown') %>
--------------------------------------------------------------------------------
/themes/vue/source/css/benchmark.styl:
--------------------------------------------------------------------------------
1 | #benchmark-results
2 | margin-bottom 2em
3 | ul
4 | list-style-type none
5 | padding 0
6 | margin-left 0
7 |
8 | .framework, .time, .bar, .inner
9 | display inline-block
10 |
11 | .framework
12 | width 4.2em
13 | //text-align right
14 | margin-right 1em
15 | font-weight 600
16 |
17 | .time
18 | width 4.2em
19 | margin-right 1em
20 |
21 | .bar
22 | width 60%
23 | &.min .inner
24 | background-color #e74c3c
25 |
26 | .inner
27 | height 3px
28 | vertical-align middle
29 | background-color #3498db
30 |
31 | @media screen and (max-width: 600px)
32 | #benchmark-results
33 | .bar
34 | width 45%
--------------------------------------------------------------------------------
/src/v2/examples/hackernews.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: HackerNews 克隆
3 | type: examples
4 | order: 10
5 | ---
6 |
7 | > HackerNews 克隆是基于 HN 的官方 firebase API 、Vue 2.0 、vue-router 和 vuex 来构建的,使用服务器端渲染。
8 |
9 | {% raw %}
10 |
15 | {% endraw %}
16 |
17 | > [Live Demo](https://vue-hn.now.sh/)
18 | > 注:如果在一段时间内没有人访问过该网站,则需要一些加载时间。
19 | >
20 | > [[Source](https://github.com/vuejs/vue-hackernews-2.0)]
21 |
22 | ## 特性
23 |
24 | - 服务器端渲染
25 | - Vue + vue-router + vuex
26 | - 服务端数据提前获取
27 | - 客户端状态 & DOM 合并
28 | - 单文件 Vue 组件
29 | - 开发时进行热加载
30 | - 生产时抽出 CSS
31 | - 使用 FLIP 动画进行实时列表更新
32 |
33 | ## 结构概览
34 |
35 |
36 |
--------------------------------------------------------------------------------
/themes/vue/source/css/_settings.styl:
--------------------------------------------------------------------------------
1 | // font faces
2 | $body-font = 'Source Sans Pro', 'Helvetica Neue', Arial, sans-serif
3 | $logo-font = 'Source Sans Pro', 'Helvetica Neue', Arial, sans-serif
4 | $code-font = 'Roboto Mono', Monaco, courier, monospace
5 |
6 | // font sizes
7 | $body-font-size = 15px
8 | $code-font-size = .8em
9 |
10 | // colors
11 | $dark = #2c3e50
12 | $medium = #34495e
13 | $light = #7f8c8d
14 | $green = #42b983
15 | $border = #dddddd
16 | $codebg = #f8f8f8
17 | $red = #ff6666
18 |
19 | $radius = 2px
20 | $content-padding-top = 30px
21 | $header-inner-height = 41px
22 | $heading-padding-vertical = 10px
23 | $header-height = $header-inner-height + $heading-padding-vertical * 2
24 | $mobile-header-height = 40px
25 | $heading-link-padding-top = $header-height + $content-padding-top
26 | $mobile-heading-link-padding-top = $mobile-header-height + $content-padding-top
27 | $h2-margin-top = 45px
28 | $h3-margin-top = 52px
29 |
--------------------------------------------------------------------------------
/themes/vue/source/css/search.styl:
--------------------------------------------------------------------------------
1 | @import '_settings'
2 |
3 | $border = #ddd
4 |
5 | .algolia-autocomplete
6 | line-height normal
7 |
8 | .aa-dropdown-menu
9 | width 100%
10 | border-color #999
11 | font-size 0.9rem
12 |
13 | @media (min-width: 768px)
14 | .aa-dropdown-menu
15 | min-width: 515px
16 |
17 | .algolia-docsearch-suggestion
18 | border-color $border
19 |
20 | .algolia-docsearch-suggestion--content
21 | color $dark
22 |
23 | .algolia-docsearch-suggestion--subcategory-column
24 | border-color $border
25 |
26 | .algolia-docsearch-suggestion--category-header
27 | background: $green
28 |
29 | .algolia-docsearch-footer
30 | border-color $border
31 |
32 | .algolia-docsearch-suggestion--category-header .algolia-docsearch-suggestion--highlight
33 | background rgba(255, 255, 255, 0.6)
34 |
35 | .algolia-docsearch-suggestion--highlight
36 | color: #2c815b
37 |
38 | .aa-cursor .algolia-docsearch-suggestion--content
39 | color: $dark
40 |
--------------------------------------------------------------------------------
/src/_posts/vue-011-release.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Vue.js 0.11 released!
3 | date: 2014-11-09 09:23:40
4 | ---
5 |
6 | After the long wait, [Vue.js 0.11 **Cowboy Bebop**](https://github.com/yyx990803/vue/releases/tag/0.11.0) is finally here! Thanks to everyone who tried out the release candidate versions and provided feedback / bug reports along the way.
7 |
8 |
9 |
10 | The 0.11 release introduced many new features and also a fair number of breaking changes, so please carefully read through the [0.11 Change List](https://github.com/yyx990803/vue/blob/master/changes.md) before upgrading. Aside from the API changes, 0.11 also ships with better [code quality](https://codeclimate.com/github/yyx990803/vue) and [test coverage](https://coveralls.io/r/yyx990803/vue), and is considerably more robust in almost every aspect.
11 |
12 | This documentation site has been fully upgraded to match the new 0.11 API. For the now legacy 0.10.6 version, you can still find documentations for it at [legacy.vuejs.org](http://legacy.vuejs.org).
13 |
--------------------------------------------------------------------------------
/themes/vue/layout/post.ejs:
--------------------------------------------------------------------------------
1 |
21 |
27 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2013-2015 Yuxi Evan You
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in
13 | all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | THE SOFTWARE.
22 |
--------------------------------------------------------------------------------
/src/v2/guide/routing.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: 路由
3 | type: guide
4 | order: 21
5 | ---
6 |
7 | ## 官方路由
8 |
9 | 对于大多数单页面应用,都推荐使用官方支持的[vue-router库](https://github.com/vuejs/vue-router)。更多细节可以看[vue-router文档](http://vuejs.github.io/vue-router/)。
10 |
11 | ## 从零开始简单的路由
12 |
13 | 如果只需要非常简单的路由而不需要引入整个路由库,可以动态渲染一个页面级的组件像这样:
14 |
15 | ``` js
16 | const NotFound = { template: 'Page not found
' }
17 | const Home = { template: 'home page
' }
18 | const About = { template: 'about page
' }
19 |
20 | const routes = {
21 | '/': Home,
22 | '/about': About
23 | }
24 |
25 | new Vue({
26 | el: '#app',
27 | data: {
28 | currentRoute: window.location.pathname
29 | },
30 | computed: {
31 | ViewComponent () {
32 | return routes[this.currentRoute] || NotFound
33 | }
34 | },
35 | render (h) { return h(this.ViewComponent) }
36 | })
37 | ```
38 | 结合HTML5 History API,你可以建立一个非常基本但功能齐全的客户端路由器。可以直接看[实例应用](https://github.com/chrisvfritz/vue-2.0-simple-routing-example)
39 |
40 | ## 整合第三方路由
41 |
42 | 如果有非常喜欢的第三方路由,如[Page.js](https://github.com/visionmedia/page.js)或者 [Director](https://github.com/flatiron/director), 整合[很简单](https://github.com/chrisvfritz/vue-2.0-simple-routing-example/compare/master...pagejs)。 这有个用了Page.js的[复杂示例](https://github.com/chrisvfritz/vue-2.0-simple-routing-example/tree/pagejs) 。
43 |
44 | ***
45 |
46 | > 原文: http://vuejs.org/guide/routing.html
47 |
48 | ***
49 |
--------------------------------------------------------------------------------
/themes/vue/layout/partials/ecosystem_dropdown.ejs:
--------------------------------------------------------------------------------
1 |
2 | 生态系统
3 |
4 | 帮助
5 |
10 | 信息
11 |
16 | 核心插件
17 |
21 | 资源列表
22 |
26 |
27 |
--------------------------------------------------------------------------------
/themes/vue/layout/page.ejs:
--------------------------------------------------------------------------------
1 | <% if (page.type) { %>
2 | <%- partial('partials/sidebar', { type: page.type, index: page.index }) %>
3 | <% } else { %>
4 |
9 | <% } %>
10 |
35 |
--------------------------------------------------------------------------------
/themes/vue/source/css/_syntax.styl:
--------------------------------------------------------------------------------
1 | .gutter pre
2 | color #999
3 |
4 | pre
5 | color: #525252
6 | .function .keyword,
7 | .constant
8 | color: #0092db
9 | .keyword,
10 | .attribute
11 | color: #e96900
12 | .number,
13 | .literal
14 | color: #AE81FF
15 | .tag,
16 | .tag .title,
17 | .change,
18 | .winutils,
19 | .flow,
20 | .lisp .title,
21 | .clojure .built_in,
22 | .nginx .title,
23 | .tex .special
24 | color: #2973b7
25 | .class .title
26 | color: white
27 | .symbol,
28 | .symbol .string,
29 | .value,
30 | .regexp
31 | color: $green
32 | .title
33 | color: #A6E22E
34 | .tag .value,
35 | .string,
36 | .subst,
37 | .haskell .type,
38 | .preprocessor,
39 | .ruby .class .parent,
40 | .built_in,
41 | .sql .aggregate,
42 | .django .template_tag,
43 | .django .variable,
44 | .smalltalk .class,
45 | .javadoc,
46 | .django .filter .argument,
47 | .smalltalk .localvars,
48 | .smalltalk .array,
49 | .attr_selector,
50 | .pseudo,
51 | .addition,
52 | .stream,
53 | .envvar,
54 | .apache .tag,
55 | .apache .cbracket,
56 | .tex .command,
57 | .prompt
58 | color: $green
59 | .comment,
60 | .java .annotation,
61 | .python .decorator,
62 | .template_comment,
63 | .pi,
64 | .doctype,
65 | .deletion,
66 | .shebang,
67 | .apache .sqbracket,
68 | .tex .formula
69 | color: #b3b3b3
70 | .coffeescript .javascript,
71 | .javascript .xml,
72 | .tex .formula,
73 | .xml .javascript,
74 | .xml .vbscript,
75 | .xml .css,
76 | .xml .cdata
77 | opacity: 0.5
--------------------------------------------------------------------------------
/themes/vue/source/css/_demo.styl:
--------------------------------------------------------------------------------
1 | #demo, .demo
2 | border 1px solid #eee
3 | border-radius $radius
4 | padding 25px 35px
5 | margin-top 1em
6 | margin-bottom 40px
7 | font-size 1.2em
8 | line-height 1.5em
9 | -webkit-user-select none
10 | -moz-user-select none
11 | -ms-user-select none
12 | user-select none
13 | overflow-x auto
14 | h1
15 | margin 0 0 .5em
16 | font-size 1.8em
17 | ul, ol
18 | padding-left 1.5em
19 | padding-bottom .2em !important
20 | &:first-child
21 | margin-top 0
22 | &:last-child
23 | margin-bottom 0
24 | li
25 | color $medium
26 | // !!TODO: Check to make sure this isn't here for a good reason.
27 | // cursor pointer
28 | // -ms-user-select none
29 | // -moz-user-select none
30 | // -webkit-user-select none
31 | &.done
32 | color $light
33 | text-decoration line-through
34 | p
35 | margin 0 !important
36 | padding 0 !important
37 | &:first-child
38 | margin-top 0
39 | &:last-child
40 | margin-bottom 0
41 | textarea
42 | width 100%
43 | resize vertical
44 |
45 |
46 |
47 | ul#demo, ul.demo
48 | li
49 | margin-left 1.5em
50 |
51 | @media screen and (max-width: 900px)
52 | #demo, .demo
53 | margin-left 0
54 |
55 | .benchmark-table
56 | margin: 0 auto
57 | text-align center
58 |
59 | tbody > tr > th
60 | text-align right
61 |
62 | th, td
63 | padding: 3px 7px
--------------------------------------------------------------------------------
/update.js:
--------------------------------------------------------------------------------
1 | var fs = require('fs')
2 | var zlib = require('zlib')
3 | var version = require('../vue/package.json').version
4 | var themeconfPath = 'themes/vue/_config.yml'
5 | var installPath = 'src/v2/guide/installation.md'
6 | var themeconfig = fs.readFileSync(themeconfPath, 'utf-8')
7 | var installation = fs.readFileSync(installPath, 'utf-8')
8 |
9 | fs.writeFileSync(
10 | themeconfPath,
11 | themeconfig.replace(/vue_version: .*/, 'vue_version: ' + version)
12 | )
13 |
14 | var sizes = {
15 | dev: 'vue.js',
16 | min: 'vue.min.js',
17 | gz: 'vue.min.js',
18 | ro_gz: 'vue.runtime.min.js'
19 | }
20 |
21 | var pending = []
22 | Object.keys(sizes).forEach(file => {
23 | var filesize = fs.statSync('../vue/dist/' + sizes[file], 'utf-8').size
24 | if (!/gz$/.test(file)) {
25 | sizes[file] = (filesize / 1024).toFixed(2)
26 | } else {
27 | pending.push(new Promise((resolve, reject) => {
28 | fs.readFile('../vue/dist/' + sizes[file], (err, buf) => {
29 | if (err) return reject(err)
30 | zlib.gzip(buf, (err, buf) => {
31 | if (err) return reject(err)
32 | sizes[file] = (buf.length / 1024).toFixed(2)
33 | resolve()
34 | })
35 | })
36 | }))
37 | }
38 | })
39 |
40 | Promise.all(pending).then(() => {
41 | fs.writeFileSync(
42 | installPath,
43 | installation
44 | .replace(/vue_version: .*/, 'vue_version: ' + version)
45 | .replace(/(\w+)_size:.*/g, function (m, p1) {
46 | return p1 + '_size: "' + sizes[p1] + '"'
47 | })
48 | )
49 | console.log(sizes)
50 | }).catch(err => {
51 | console.error(err)
52 | })
53 |
--------------------------------------------------------------------------------
/src/v2/guide/deployment.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: 生产环境部署
3 | type: guide
4 | order: 20
5 | ---
6 |
7 | ## 删除警告
8 |
9 | 为了减少文件大小,Vue 精简独立版本已经删除了所有警告,但是当你使用 Webpack 或 Browserify 等工具时,你需要一些额外的配置实现这点。
10 |
11 | ### Webpack
12 |
13 | 使用 Webpack 的 [DefinePlugin](http://webpack.github.io/docs/list-of-plugins.html#defineplugin) 来指定生产环境,以便在压缩时可以让 UglifyJS 自动删除代码块内的警告语句。例如配置:
14 |
15 | ``` js
16 | var webpack = require('webpack')
17 |
18 | module.exports = {
19 | // ...
20 | plugins: [
21 | // ...
22 | new webpack.DefinePlugin({
23 | 'process.env': {
24 | NODE_ENV: '"production"'
25 | }
26 | }),
27 | new webpack.optimize.UglifyJsPlugin({
28 | compress: {
29 | warnings: false
30 | }
31 | })
32 | ]
33 | }
34 | ```
35 |
36 | ### Browserify
37 |
38 | - 运行打包命令,设置 `NODE_ENV` 为 `"production"`。等于告诉 `vueify` 避免引入热重载和开发相关代码。
39 | - 使用一个全局 [envify](https://github.com/hughsk/envify) 转换你的 bundle 文件。这可以精简掉包含在 Vue 源码中所有环境变量条件相关代码块内的警告语句。例如:
40 |
41 |
42 | ``` bash
43 | NODE_ENV=production browserify -g envify -e main.js | uglifyjs -c -m > build.js
44 | ```
45 |
46 | - 使用 vueify 中包含的 extract-css 插件,提取样式到单独的css文件。
47 |
48 | ``` bash
49 | NODE_ENV=production browserify -g envify -p [ vueify/plugins/extract-css -o build.css ] -e main.js | uglifyjs -c -m > build.js
50 | ```
51 |
52 | ## 跟踪运行时错误
53 |
54 | 如果在组件渲染时出现运行错误,错误将会被传递至全局 `Vue.config.errorHandler` 配置函数(如果已设置)。利用这个钩子函数和错误跟踪服务(如 [Sentry](https://sentry.io),它为 Vue 提供[官方集成](https://sentry.io/for/vue/)),可能是个不错的主意。
55 |
56 | ## 提取 CSS
57 |
58 | 使用[单文件组件](./single-file-components.html)时,`
26 |
27 |
28 |
--------------------------------------------------------------------------------
/src/_posts/march-update.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: March 2016 Update
3 | date: 2016-03-14 18:45:00
4 | ---
5 |
6 | ## Growing Community
7 |
8 | Vue's growth in the past year has been nothing short of amazing. As of today we are at over 15,000 stars on GitHub, over 500k downloads from npm, and over 2,000 users in the Gitter channel. What's more exciting though, is that the community successfully organized the first [London Vue.js Meetup](http://www.meetup.com/London-Vue-js-Meetup/) and the first [Paris Vue.js Meetup](http://www.meetup.com/Vuejs-Paris/?scroll=true)! A big shoutout to the awesome organizers: [Jack](https://twitter.com/JackBarham), [James](https://twitter.com/onejamesbrowne/) and [Eduardo](https://twitter.com/posva/).
9 |
10 |
11 |
12 | If you are interested in connecting with Vue.js users near you and share your experiences in using Vue.js, joining a local Meetup is a great idea - even better, maybe you can organize one :)
13 |
14 | ## Cool Things Being Built
15 |
16 | More and more amazing things are being built with Vue. There are products like [PageKit](https://pagekit.com/), Laravel Spark (coming soon) and [Statamic](https://v2.statamic.com/), sleek apps like [Koel](http://koel.phanan.net/) and [Gokotta](https://github.com/Zhangdroid/Gokotta), UI components like [VueStrap](http://yuche.github.io/vue-strap/) and [Vue-MDL](http://posva.net/vue-mdl/), and smooth, interactive experiences like [YouTube Adblitz](https://adblitz.withyoutube.com) and even the [Facebook NewsFeed Marketing Site](https://newsfeed.fb.com/)!
17 |
18 | There are many other great projects - too many to be listed here - but you can check them all out in [awesome-vue](https://github.com/vuejs/awesome-vue). If you've built great things with Vue, you should also add them to the list!
19 |
20 | ## A New Vision For the Project
21 |
22 | Some of you may have noticed that the development on the Vue.js core repo has slowed down lately - in the meanwhile, a lot of efforts went into other sub projects, namely [Vuex](https://github.com/vuejs/vuex), [vue-devtools](https://github.com/vuejs/vue-devtools) and the official [Webpack project boilerplate](https://github.com/vuejs-templates/webpack). The next step is a new release for [vue-router](https://github.com/vuejs/vue-router), and better documentation/examples demonstrating how Vue.js core, Vuex and vue-router work together in a large single page application.
23 |
24 | All this adds together towards a new vision for the Vue.js project: a progressive framework that can adapt to different complexity levels. Vue.js core will remain "just the view layer" - you can still drop it on whatever existing page to replace jQuery, but the Vue.js project also includes other pieces like vue-router, Vuex, vue-loader/vueify and vue-cli that works together as a more complete, opinionated framework for single page applications. More on this in a later post.
25 |
26 | ## Vue.js needs your help!
27 |
28 | Open source is awesome, and I'm proud that Vue.js is helping people build real products all over the world. However, as the scope of the project grows, pushing new features while maintaining everything becomes a very demanding job. The good news is you can help!
29 |
30 | ### Looking for collaborators
31 |
32 | There are already users who frequently helps out in various ways, but this is an invitation to make things official. I'm looking for contributors to join the "team", which is currently mostly just me. If that sounds interesting to you, take a look at the application [here](https://docs.google.com/forms/d/1SgDgKZqyivEf5xl0EOWNfs68Xy3f4oBzLXIlwlS0BIs/viewform).
33 |
34 | ### Looking for sponsors
35 |
36 | Another way to help making Vue development sustainable is providing direct financial support. The more financial support I receive, the more time I get to spend on making Vue even better.
37 |
38 | If you run a business and is using Vue in a revenue-generating product, it would make business sense to sponsor Vue development: it ensures the project that your product relies on stays healthy and actively maintained. It can also help your exposure in the Vue community and makes it easier to attract Vue developers.
39 |
40 | If you are an individual user and have enjoyed the productivity of using Vue, consider donating as a sign of appreciation - like buying me coffee once in a while :)
41 |
42 | In either case, you can provide recurring funding through Vue's [Patreon campaign](https://www.patreon.com/evanyou), or provide one-time donations via [PayPal](https://www.paypal.me/evanyou). There are many ideas for Vue that I have lined up but haven't had the time to embark on, and I would love to be able to work on them full time - I hope you can help me make that happen!
43 |
--------------------------------------------------------------------------------
/src/v2/guide/custom-directive.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: 自定义指令
3 | type: guide
4 | order: 16
5 | ---
6 |
7 | ## 简介
8 |
9 | 除了默认设置的核心指令( `v-model` 和 `v-show` ),Vue 也允许注册自定义指令。注意,在 Vue2.0 里面,代码复用的主要形式和抽象是组件——然而,有的情况下,你仍然需要对纯 DOM 元素进行底层操作,这时候就会用到自定义指令。下面这个例子将聚焦一个 input 元素,像这样:
10 |
11 | {% raw %}
12 |
13 |
14 |
15 |
25 | {% endraw %}
26 |
27 | 当页面加载时,元素将获得焦点。事实上,你访问后还没点击任何内容,input 就获得了焦点。现在让我们完善这个指令:
28 |
29 | ``` js
30 | // 注册一个全局自定义指令 v-focus
31 | Vue.directive('focus', {
32 | // 当绑定元素插入到 DOM 中。
33 | inserted: function (el) {
34 | // 聚焦元素
35 | el.focus()
36 | }
37 | })
38 | ```
39 |
40 | 也可以注册局部指令,组件中接受一个 `directives` 的选项:
41 |
42 | ``` js
43 | directives: {
44 | focus: {
45 | // 指令的定义---
46 |
47 | }
48 | }
49 | ```
50 |
51 | 然后你可以在模板中任何元素上使用新的 `v-focus` 属性:
52 |
53 | ``` html
54 |
55 | ```
56 |
57 | ## 钩子函数
58 |
59 | 指令定义函数提供了几个钩子函数(可选):
60 |
61 | - `bind`: 只调用一次,指令第一次绑定到元素时调用,用这个钩子函数可以定义一个在绑定时执行一次的初始化动作。
62 |
63 | - `inserted`: 被绑定元素插入父节点时调用(父节点存在即可调用,不必存在于 document 中)。
64 |
65 | - `update`: 被绑定元素所在的模板更新时调用,而不论绑定值是否变化。通过比较更新前后的绑定值,可以忽略不必要的模板更新(详细的钩子函数参数见下)。
66 |
67 | - `componentUpdated`: 被绑定元素所在模板完成一次更新周期时调用。
68 |
69 | - `unbind`: 只调用一次, 指令与元素解绑时调用。
70 |
71 | 接下来我们来看一下钩子函数的参数 (包括 `el`,`binding`,`vnode`,`oldVnode`) 。
72 |
73 | ## 钩子函数参数
74 |
75 | 钩子函数被赋予了以下参数:
76 |
77 | - **el**: 指令所绑定的元素,可以用来直接操作 DOM 。
78 | - **binding**: 一个对象,包含以下属性:
79 | - **name**: 指令名,不包括 `v-` 前缀。
80 | - **value**: 指令的绑定值, 例如: `v-my-directive="1 + 1"`, value 的值是 `2`。
81 | - **oldValue**: 指令绑定的前一个值,仅在 `update` 和 `componentUpdated` 钩子中可用。无论值是否改变都可用。
82 | - **expression**: 绑定值的字符串形式。 例如 `v-my-directive="1 + 1"` , expression 的值是 `"1 + 1"`。
83 | - **arg**: 传给指令的参数。例如 `v-my-directive:foo`, arg 的值是 `"foo"`。
84 | - **modifiers**: 一个包含修饰符的对象。 例如: `v-my-directive.foo.bar`, 修饰符对象 modifiers 的值是 `{ foo: true, bar: true }`。
85 | - **vnode**: Vue 编译生成的虚拟节点,查阅 [VNode API](../api/#VNode接口) 了解更多详情。
86 | - **oldVnode**: 上一个虚拟节点,仅在 `update` 和 `componentUpdated` 钩子中可用。
87 |
88 | 除了 `el` 之外,其它参数都应该是只读的,尽量不要修改他们。如果需要在钩子之间共享数据,建议通过元素的 [dataset](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/dataset) 来进行。
89 |
90 | 一个使用了这些参数的自定义钩子样例:
91 |
92 | ``` html
93 |
94 | ```
95 |
96 | ``` js
97 | Vue.directive('demo', {
98 | bind: function (el, binding, vnode) {
99 | var s = JSON.stringify
100 | el.innerHTML =
101 | 'name: ' + s(binding.name) + ' ' +
102 | 'value: ' + s(binding.value) + ' ' +
103 | 'expression: ' + s(binding.expression) + ' ' +
104 | 'argument: ' + s(binding.arg) + ' ' +
105 | 'modifiers: ' + s(binding.modifiers) + ' ' +
106 | 'vnode keys: ' + Object.keys(vnode).join(', ')
107 | }
108 | })
109 |
110 | new Vue({
111 | el: '#hook-arguments-example',
112 | data: {
113 | message: 'hello!'
114 | }
115 | })
116 | ```
117 |
118 | {% raw %}
119 |
120 |
140 | {% endraw %}
141 |
142 | ## 函数简写
143 |
144 | 大多数情况下,我们可能想在 `bind` 和 `update` 钩子上做重复动作,并且不想关心其它的钩子函数。可以这样写:
145 |
146 | ``` js
147 | Vue.directive('color-swatch', function (el, binding) {
148 | el.style.backgroundColor = binding.value
149 | })
150 | ```
151 | ## 对象字面量
152 |
153 | 如果指令需要多个值,可以传入一个 JavaScript 对象字面量。记住,指令函数能够接受所有合法类型的 JavaScript 表达式。
154 |
155 | ``` html
156 |
157 | ```
158 |
159 | ``` js
160 | Vue.directive('demo', function (el, binding) {
161 | console.log(binding.value.color) // => "white"
162 | console.log(binding.value.text) // => "hello!"
163 | })
164 | ```
165 |
166 | ***
167 |
168 | > 原文:http://vuejs.org/guide/custom-directive.html
169 |
170 | ***
171 |
--------------------------------------------------------------------------------
/themes/vue/source/js/smooth-scroll.min.js:
--------------------------------------------------------------------------------
1 | /*! smooth-scroll v10.2.1 | (c) 2016 Chris Ferdinandi | MIT License | http://github.com/cferdinandi/smooth-scroll */
2 | !(function(e,t){"function"==typeof define&&define.amd?define([],t(e)):"object"==typeof exports?module.exports=t(e):e.smoothScroll=t(e)})("undefined"!=typeof global?global:this.window||this.global,(function(e){"use strict";var t,n,o,r,a,c,l,i={},u="querySelector"in document&&"addEventListener"in e,s={selector:"[data-scroll]",selectorHeader:null,speed:500,easing:"easeInOutCubic",offset:0,callback:function(){}},d=function(){var e={},t=!1,n=0,o=arguments.length;"[object Boolean]"===Object.prototype.toString.call(arguments[0])&&(t=arguments[0],n++);for(var r=function(n){for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(t&&"[object Object]"===Object.prototype.toString.call(n[o])?e[o]=d(!0,e[o],n[o]):e[o]=n[o])};n=0&&t.item(n)!==this;);return n>-1});e&&e!==document;e=e.parentNode)if(e.matches(t))return e;return null},m=function(e){"#"===e.charAt(0)&&(e=e.substr(1));for(var t,n=String(e),o=n.length,r=-1,a="",c=n.charCodeAt(0);++r=1&&t<=31||127==t||0===r&&t>=48&&t<=57||1===r&&t>=48&&t<=57&&45===c?"\\"+t.toString(16)+" ":t>=128||45===t||95===t||t>=48&&t<=57||t>=65&&t<=90||t>=97&&t<=122?n.charAt(r):"\\"+n.charAt(r)}return"#"+a},p=function(e,t){var n;return"easeInQuad"===e&&(n=t*t),"easeOutQuad"===e&&(n=t*(2-t)),"easeInOutQuad"===e&&(n=t<.5?2*t*t:-1+(4-2*t)*t),"easeInCubic"===e&&(n=t*t*t),"easeOutCubic"===e&&(n=--t*t*t+1),"easeInOutCubic"===e&&(n=t<.5?4*t*t*t:(t-1)*(2*t-2)*(2*t-2)+1),"easeInQuart"===e&&(n=t*t*t*t),"easeOutQuart"===e&&(n=1- --t*t*t*t),"easeInOutQuart"===e&&(n=t<.5?8*t*t*t*t:1-8*--t*t*t*t),"easeInQuint"===e&&(n=t*t*t*t*t),"easeOutQuint"===e&&(n=1+--t*t*t*t*t),"easeInOutQuint"===e&&(n=t<.5?16*t*t*t*t*t:1+16*--t*t*t*t*t),n||t},g=function(e,t,n){var o=0;if(e.offsetParent)do o+=e.offsetTop,e=e.offsetParent;while(e);return o=Math.max(o-t-n,0),Math.min(o,v()-b())},b=function(){return Math.max(document.documentElement.clientHeight,e.innerHeight||0)},v=function(){return Math.max(document.body.scrollHeight,document.documentElement.scrollHeight,document.body.offsetHeight,document.documentElement.offsetHeight,document.body.clientHeight,document.documentElement.clientHeight)},y=function(e){return e&&"object"==typeof JSON&&"function"==typeof JSON.parse?JSON.parse(e):{}},O=function(e){return e?f(e)+e.offsetTop:0},S=function(t,n,o){o||(t.focus(),document.activeElement.id!==t.id&&(t.setAttribute("tabindex","-1"),t.focus(),t.style.outline="none"),e.scrollTo(0,n))};i.animateScroll=function(n,o,c){var i=y(o?o.getAttribute("data-options"):null),u=d(t||s,c||{},i),f="[object Number]"===Object.prototype.toString.call(n),h=f||!n.tagName?null:n;if(f||h){var m=e.pageYOffset;u.selectorHeader&&!r&&(r=document.querySelector(u.selectorHeader)),a||(a=O(r));var b,E,I=f?n:g(h,a,parseInt(u.offset,10)),H=I-m,A=v(),j=0,C=function(t,r,a){var c=e.pageYOffset;(t==r||c==r||e.innerHeight+c>=A)&&(clearInterval(a),S(n,r,f),u.callback(n,o))},M=function(){j+=16,b=j/parseInt(u.speed,10),b=b>1?1:b,E=m+H*p(u.easing,b),e.scrollTo(0,Math.floor(E)),C(E,I,l)},w=function(){clearInterval(l),l=setInterval(M,16)};0===e.pageYOffset&&e.scrollTo(0,0),w()}};var E=function(t){var r;try{r=m(decodeURIComponent(e.location.hash))}catch(t){r=m(e.location.hash)}n&&(n.id=n.getAttribute("data-scroll-id"),i.animateScroll(n,o),n=null,o=null)},I=function(r){if(0===r.button&&!r.metaKey&&!r.ctrlKey&&(o=h(r.target,t.selector),o&&"a"===o.tagName.toLowerCase()&&o.hostname===e.location.hostname&&o.pathname===e.location.pathname&&/#/.test(o.href))){var a;try{a=m(decodeURIComponent(o.hash))}catch(e){a=m(o.hash)}if("#"===a){r.preventDefault(),n=document.body;var c=n.id?n.id:"smooth-scroll-top";return n.setAttribute("data-scroll-id",c),n.id="",void(e.location.hash.substring(1)===c?E():e.location.hash=c)}n=document.querySelector(a),n&&(n.setAttribute("data-scroll-id",n.id),n.id="",o.hash===e.location.hash&&(r.preventDefault(),E()))}},H=function(e){c||(c=setTimeout((function(){c=null,a=O(r)}),66))};return i.destroy=function(){t&&(document.removeEventListener("click",I,!1),e.removeEventListener("resize",H,!1),t=null,n=null,o=null,r=null,a=null,c=null,l=null)},i.init=function(n){u&&(i.destroy(),t=d(s,n||{}),r=t.selectorHeader?document.querySelector(t.selectorHeader):null,a=O(r),document.addEventListener("click",I,!1),e.addEventListener("hashchange",E,!1),r&&e.addEventListener("resize",H,!1))},i}));
3 |
--------------------------------------------------------------------------------
/themes/vue/source/fonts/Source_Sans_Pro/OFL.txt:
--------------------------------------------------------------------------------
1 | Copyright 2010, 2012 Adobe Systems Incorporated (http://www.adobe.com/), with Reserved Font Name 'Source'. All Rights Reserved. Source is a trademark of Adobe Systems Incorporated in the United States and/or other countries.
2 | This Font Software is licensed under the SIL Open Font License, Version 1.1.
3 | This license is copied below, and is also available with a FAQ at:
4 | http://scripts.sil.org/OFL
5 |
6 |
7 | -----------------------------------------------------------
8 | SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
9 | -----------------------------------------------------------
10 |
11 | PREAMBLE
12 | The goals of the Open Font License (OFL) are to stimulate worldwide
13 | development of collaborative font projects, to support the font creation
14 | efforts of academic and linguistic communities, and to provide a free and
15 | open framework in which fonts may be shared and improved in partnership
16 | with others.
17 |
18 | The OFL allows the licensed fonts to be used, studied, modified and
19 | redistributed freely as long as they are not sold by themselves. The
20 | fonts, including any derivative works, can be bundled, embedded,
21 | redistributed and/or sold with any software provided that any reserved
22 | names are not used by derivative works. The fonts and derivatives,
23 | however, cannot be released under any other type of license. The
24 | requirement for fonts to remain under this license does not apply
25 | to any document created using the fonts or their derivatives.
26 |
27 | DEFINITIONS
28 | "Font Software" refers to the set of files released by the Copyright
29 | Holder(s) under this license and clearly marked as such. This may
30 | include source files, build scripts and documentation.
31 |
32 | "Reserved Font Name" refers to any names specified as such after the
33 | copyright statement(s).
34 |
35 | "Original Version" refers to the collection of Font Software components as
36 | distributed by the Copyright Holder(s).
37 |
38 | "Modified Version" refers to any derivative made by adding to, deleting,
39 | or substituting -- in part or in whole -- any of the components of the
40 | Original Version, by changing formats or by porting the Font Software to a
41 | new environment.
42 |
43 | "Author" refers to any designer, engineer, programmer, technical
44 | writer or other person who contributed to the Font Software.
45 |
46 | PERMISSION & CONDITIONS
47 | Permission is hereby granted, free of charge, to any person obtaining
48 | a copy of the Font Software, to use, study, copy, merge, embed, modify,
49 | redistribute, and sell modified and unmodified copies of the Font
50 | Software, subject to the following conditions:
51 |
52 | 1) Neither the Font Software nor any of its individual components,
53 | in Original or Modified Versions, may be sold by itself.
54 |
55 | 2) Original or Modified Versions of the Font Software may be bundled,
56 | redistributed and/or sold with any software, provided that each copy
57 | contains the above copyright notice and this license. These can be
58 | included either as stand-alone text files, human-readable headers or
59 | in the appropriate machine-readable metadata fields within text or
60 | binary files as long as those fields can be easily viewed by the user.
61 |
62 | 3) No Modified Version of the Font Software may use the Reserved Font
63 | Name(s) unless explicit written permission is granted by the corresponding
64 | Copyright Holder. This restriction only applies to the primary font name as
65 | presented to the users.
66 |
67 | 4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
68 | Software shall not be used to promote, endorse or advertise any
69 | Modified Version, except to acknowledge the contribution(s) of the
70 | Copyright Holder(s) and the Author(s) or with their explicit written
71 | permission.
72 |
73 | 5) The Font Software, modified or unmodified, in part or in whole,
74 | must be distributed entirely under this license, and must not be
75 | distributed under any other license. The requirement for fonts to
76 | remain under this license does not apply to any document created
77 | using the Font Software.
78 |
79 | TERMINATION
80 | This license becomes null and void if any of the above conditions are
81 | not met.
82 |
83 | DISCLAIMER
84 | THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
85 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
86 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
87 | OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
88 | COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
89 | INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
90 | DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
91 | FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
92 | OTHER DEALINGS IN THE FONT SOFTWARE.
93 |
--------------------------------------------------------------------------------
/src/v2/guide/syntax.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: 模板语法
3 | type: guide
4 | order: 4
5 | ---
6 |
7 | Vue.js 使用了基于 HTML 的模版语法,允许开发者声明式地将 DOM 绑定至底层 Vue 实例的数据。所有 Vue.js 的模板都是合法的 HTML ,所以能被遵循规范的浏览器和 HTML 解析器解析。
8 |
9 | 在底层的实现上, Vue 将模板编译成虚拟 DOM 渲染函数。结合响应系统,在应用状态改变时, Vue 能够智能地计算出重新渲染组件的最小代价并应用到 DOM 操作上。
10 |
11 | 如果你熟悉虚拟 DOM 并且偏爱 JavaScript 的原始力量,你也可以不用模板,[直接写渲染(render)函数](render-function.html),使用可选的 JSX 语法。
12 |
13 | ## 插值
14 |
15 | ### 文本
16 |
17 | 数据绑定最常见的形式就是使用 “Mustache” 语法(双大括号)的文本插值:
18 |
19 | ``` html
20 | Message: {{ msg }}
21 | ```
22 |
23 | Mustache 标签将会被替代为对应数据对象上 `msg` 属性的值。无论何时,绑定的数据对象上 `msg` 属性发生了改变,插值处的内容都会更新。
24 |
25 | 通过使用 [v-once 指令](../api/#v-once),你也能执行一次性地插值,当数据改变时,插值处的内容不会更新。但请留心这会影响到该节点上所有的数据绑定:
26 |
27 | ``` html
28 | This will never change: {{ msg }}
29 | ```
30 |
31 | ### 纯 HTML
32 |
33 | 双大括号会将数据解释为纯文本,而非 HTML 。为了输出真正的 HTML ,你需要使用 `v-html` 指令:
34 |
35 | ``` html
36 |
37 | ```
38 |
39 | 被插入的内容都会被当做 HTML —— 数据绑定会被忽略。注意,你不能使用 `v-html` 来复合局部模板,因为 Vue 不是基于字符串的模板引擎。组件更适合担任 UI 重用与复合的基本单元。
40 |
41 | 你的站点上动态渲染的任意 HTML 可能会非常危险,因为它很容易导致 [XSS 攻击](https://en.wikipedia.org/wiki/Cross-site_scripting)。请只对可信内容使用 HTML 插值,**绝不要**对用户提供的内容插值。
42 |
43 | ### 属性
44 |
45 | Mustache 不能在 HTML 属性中使用,应使用 [v-bind 指令](../api/#v-bind):
46 |
47 | ``` html
48 |
49 | ```
50 |
51 | 这对布尔值的属性也有效 —— 如果条件被求值为 false 的话该属性会被移除:
52 |
53 | ``` html
54 | Button
55 | ```
56 |
57 | ### 使用 JavaScript 表达式
58 |
59 | 迄今为止,在我们的模板中,我们一直都只绑定简单的属性键值。但实际上,对于所有的数据绑定, Vue.js 都提供了完全的 JavaScript 表达式支持。
60 |
61 | ``` html
62 | {{ number + 1 }}
63 |
64 | {{ ok ? 'YES' : 'NO' }}
65 |
66 | {{ message.split('').reverse().join('') }}
67 |
68 |
69 | ```
70 |
71 | 这些表达式会在所属 Vue 实例的数据作用域下作为 JavaScript 被解析。有个限制就是,每个绑定都只能包含**单个表达式**,所以下面的例子都**不会**生效。
72 |
73 | ``` html
74 |
75 | {{ var a = 1 }}
76 |
77 |
78 | {{ if (ok) { return message } }}
79 | ```
80 |
81 | 模板表达式都被放在沙盒中,只能访问全局变量的一个白名单,如 `Math` 和 `Date` 。你不应该在模板表达式中试图访问用户定义的全局变量。
82 |
83 |
84 | ## 指令
85 |
86 | 指令(Directives)是带有 `v-` 前缀的特殊属性。指令属性的值预期是**单一 JavaScript 表达式**(除了 `v-for`,之后再讨论)。指令的职责就是当其表达式的值改变时相应地将某些行为应用到 DOM 上。让我们回顾一下在介绍里的例子:
87 |
88 | ``` html
89 | Now you see me
90 | ```
91 |
92 | 这里, `v-if` 指令将根据表达式 `seen` 的值的真假来移除/插入 `` 元素。
93 |
94 | ### 参数
95 |
96 | 一些指令能接受一个“参数”,在指令后以冒号指明。例如, `v-bind` 指令被用来响应地更新 HTML 属性:
97 |
98 | ``` html
99 |
100 | ```
101 |
102 | 在这里 `href` 是参数,告知 `v-bind` 指令将该元素的 `href` 属性与表达式 `url` 的值绑定。
103 |
104 | 另一个例子是 `v-on` 指令,它用于监听 DOM 事件:
105 |
106 | ``` html
107 |
108 | ```
109 |
110 | 在这里参数是监听的事件名。我们也会更详细地讨论事件处理。
111 |
112 | ### 修饰符
113 |
114 | 修饰符(Modifiers)是以半角句号 `.` 指明的特殊后缀,用于指出一个指令应该以特殊方式绑定。例如,`.prevent` 修饰符告诉 `v-on` 指令对于触发的事件调用 `event.preventDefault()`:
115 |
116 | ``` html
117 |
118 | ```
119 |
120 | 之后当我们更深入地了解 `v-on` 与 `v-model`时,会看到更多修饰符的使用。
121 |
122 | ## 过滤器
123 |
124 | Vue.js 允许你自定义过滤器,可被用作一些常见的文本格式化。过滤器可以用在两个地方:**mustache 插值和 `v-bind` 表达式**。过滤器应该被添加在 JavaScript 表达式的尾部,由“管道”符指示:
125 |
126 | ``` html
127 |
128 | {{ message | capitalize }}
129 |
130 |
131 |
132 | ```
133 |
134 | Vue 2.x 中,过滤器只能在 mustache 绑定和 `v-bind` 表达式(从 2.1.0 开始支持)中使用,因为过滤器设计目的就是用于文本转换。为了在其他指令中实现更复杂的数据变换,你应该使用[计算属性](computed.html)。
135 |
136 | 过滤器函数总接受表达式的值作为第一个参数。
137 |
138 |
139 | ``` js
140 | new Vue({
141 | // ...
142 | filters: {
143 | capitalize: function (value) {
144 | if (!value) return ''
145 | value = value.toString()
146 | return value.charAt(0).toUpperCase() + value.slice(1)
147 | }
148 | }
149 | })
150 | ```
151 |
152 | 过滤器可以串联:
153 |
154 | ``` html
155 | {{ message | filterA | filterB }}
156 | ```
157 |
158 | 过滤器是 JavaScript 函数,因此可以接受参数:
159 |
160 | ``` html
161 | {{ message | filterA('arg1', arg2) }}
162 | ```
163 |
164 |
165 | 这里,字符串 `'arg1'` 将传给过滤器作为第二个参数, `arg2` 表达式的值将被求值然后传给过滤器作为第三个参数。
166 |
167 | ## 缩写
168 |
169 | `v-` 前缀在模板中是作为一个标示 Vue 特殊属性的明显标识。当你使用 Vue.js 为现有的标记添加动态行为时,它会很有用,但对于一些经常使用的指令来说有点繁琐。同时,当搭建 Vue.js 管理所有模板的 [SPA](https://en.wikipedia.org/wiki/Single-page_application) 时,`v-` 前缀也变得没那么重要了。因此,Vue.js 为两个最为常用的指令提供了特别的缩写:
170 |
171 | ### `v-bind` 缩写
172 |
173 | ``` html
174 |
175 |
176 |
177 |
178 |
179 | ```
180 |
181 | ### `v-on` 缩写
182 |
183 | ``` html
184 |
185 |
186 |
187 |
188 |
189 | ```
190 |
191 | 它们看起来可能与普通的 HTML 略有不同,但 `:` 与 `@` 对于属性名来说都是合法字符,在所有支持 Vue.js 的浏览器都能被正确地解析。而且,它们不会出现在最终渲染的标记。缩写语法是完全可选的,但随着你更深入地了解它们的作用,你会庆幸拥有它们。
192 |
193 | ***
194 |
195 | > 原文: http://vuejs.org/guide/syntax.html
196 |
197 | ***
198 |
--------------------------------------------------------------------------------
/_config.yml:
--------------------------------------------------------------------------------
1 | # Hexo Configuration
2 | ## Docs: http://zespia.tw/hexo/docs/configuration.html
3 | ## Source: https://github.com/tommy351/hexo/
4 |
5 | # Site
6 | title: Vue.js
7 | subtitle:
8 | description: "The Progressive JavaScript Framework"
9 | author: Evan You
10 | email:
11 | language: zh-CN
12 |
13 | # URL
14 | ## If your site is put in a subdirectory, set url as 'http://yoursite.com/child' and root as '/child/'
15 | url: https://cn.vuejs.org
16 | root: /
17 | permalink: :year/:month/:day/:title/
18 | tag_dir: tags
19 | archive_dir: archives
20 | category_dir: categories
21 | code_dir: downloads/code
22 |
23 | # Directory
24 | source_dir: src
25 | public_dir: public
26 |
27 | # Writing
28 | new_post_name: :title.md # File name of new posts
29 | default_layout: post
30 | auto_spacing: false # Add spaces between asian characters and western characters
31 | titlecase: false # Transform title into titlecase
32 | external_link: true # Open external links in new tab
33 | max_open_file: 100
34 | multi_thread: true
35 | filename_case: 0
36 | render_drafts: false
37 | post_asset_folder: false
38 | highlight:
39 | enable: true
40 | line_number: false
41 | tab_replace:
42 |
43 | # Category & Tag
44 | default_category: uncategorized
45 | category_map:
46 | tag_map:
47 |
48 | # Archives
49 | ## 2: Enable pagination
50 | ## 1: Disable pagination
51 | ## 0: Fully Disable
52 | archive: 0
53 | category: 0
54 | tag: 0
55 |
56 | # Server
57 | ## Hexo uses Connect as a server
58 | ## You can customize the logger format as defined in
59 | ## http://www.senchalabs.org/connect/logger.html
60 | port: 4000
61 | logger: false
62 | logger_format:
63 |
64 | # Date / Time format
65 | ## Hexo uses Moment.js to parse and display date
66 | ## You can customize the date format as defined in
67 | ## http://momentjs.com/docs/#/displaying/format/
68 | date_format: MMM D YYYY
69 | time_format: H:mm:ss
70 |
71 | # Pagination
72 | ## Set per_page to 0 to disable pagination
73 | per_page: 10
74 | pagination_dir: page
75 |
76 | # Disqus
77 | disqus_shortname:
78 |
79 | # Extensions
80 | ## Plugins: https://github.com/tommy351/hexo/wiki/Plugins
81 | ## Themes: https://github.com/tommy351/hexo/wiki/Themes
82 | theme: vue
83 | exclude_generator:
84 |
85 | # Markdown
86 | ## https://github.com/chjj/marked
87 | markdown:
88 | gfm: true
89 | pedantic: false
90 | sanitize: false
91 | tables: true
92 | breaks: true
93 | smartLists: true
94 | smartypants: true
95 |
96 | # Deployment
97 | ## Docs: http://zespia.tw/hexo/docs/deployment.html
98 | deploy:
99 | type: git
100 | repository: git@github.com:vuejs/cn.vuejs.org.git
101 | branch: gh-pages
102 |
103 | feed:
104 | type: atom
105 | path: atom.xml
106 | limit: 20
107 |
108 | alias:
109 | api/index.html: v2/api/index.html
110 | guide/class-and-style.html: v2/guide/class-and-style.html
111 | guide/comparison.html: v2/guide/comparison.html
112 | guide/components.html: v2/guide/components.html
113 | guide/computed.html: v2/guide/computed.html
114 | guide/conditional.html: v2/guide/conditional.html
115 | guide/custom-directive.html: v2/guide/custom-directive.html
116 | guide/deployment.html: v2/guide/deployment.html
117 | guide/events.html: v2/guide/events.html
118 | guide/forms.html: v2/guide/forms.html
119 | guide/index.html: v2/guide/index.html
120 | guide/installation.html: v2/guide/installation.html
121 | guide/instance.html: v2/guide/instance.html
122 | guide/join.html: v2/guide/join.html
123 | guide/list.html: v2/guide/list.html
124 | guide/migration-vue-router.html: v2/guide/migration-vue-router.html
125 | guide/migration-vuex.html: v2/guide/migration-vuex.html
126 | guide/migration.html: v2/guide/migration.html
127 | guide/mixins.html: v2/guide/mixins.html
128 | guide/plugins.html: v2/guide/plugins.html
129 | guide/reactivity.html: v2/guide/reactivity.html
130 | guide/render-function.html: v2/guide/render-function.html
131 | guide/routing.html: v2/guide/routing.html
132 | guide/single-file-components.html: v2/guide/single-file-components.html
133 | guide/ssr.html: v2/guide/ssr.html
134 | guide/state-management.html: v2/guide/state-management.html
135 | guide/syntax.html: v2/guide/syntax.html
136 | guide/transitioning-state.html: v2/guide/transitioning-state.html
137 | guide/transitions.html: v2/guide/transitions.html
138 | guide/unit-testing.html: v2/guide/unit-testing.html
139 | examples/commits.html: v2/examples/commits.html
140 | examples/elastic-header.html: v2/examples/elastic-header.html
141 | examples/firebase.html: v2/examples/firebase.html
142 | examples/grid-component.html: v2/examples/grid-component.html
143 | examples/hackernews.html: v2/examples/hackernews.html
144 | examples/index.html: v2/examples/index.html
145 | examples/modal.html: v2/examples/modal.html
146 | examples/select2.html: v2/examples/select2.html
147 | examples/svg.html: v2/examples/svg.html
148 | examples/todomvc.html: v2/examples/todomvc.html
149 | examples/tree-view.html: v2/examples/tree-view.html
150 |
151 |
--------------------------------------------------------------------------------
/src/v2/guide/conditional.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: 条件渲染
3 | type: guide
4 | order: 7
5 | ---
6 |
7 | ## `v-if`
8 |
9 | 在字符串模板中,如 Handlebars ,我们得像这样写一个条件块:
10 |
11 | ``` html
12 |
13 | {{#if ok}}
14 |
Yes
15 | {{/if}}
16 | ```
17 |
18 | 在 Vue.js ,我们使用 `v-if` 指令实现同样的功能:
19 |
20 | ``` html
21 | Yes
22 | ```
23 |
24 | 也可以用 `v-else` 添加一个 "else" 块:
25 |
26 | ``` html
27 | Yes
28 | No
29 | ```
30 |
31 | ### `` 中 `v-if` 条件组
32 |
33 | 因为 `v-if` 是一个指令,需要将它添加到一个元素上。但是如果我们想切换多个元素呢?此时我们可以把一个 `` 元素当做包装元素,并在上面使用 `v-if`。最终的渲染结果不会包含 `` 元素。
34 |
35 | ``` html
36 |
37 | Title
38 | Paragraph 1
39 | Paragraph 2
40 |
41 | ```
42 |
43 | ### `v-else`
44 |
45 | 你可以使用 `v-else` 指令来表示 `v-if` 的“else 块”:
46 |
47 | ``` html
48 |
49 | Now you see me
50 |
51 |
52 | Now you don't
53 |
54 | ```
55 |
56 | `v-else` 元素必须紧跟在 `v-if` 或者 `v-else-if` 元素的后面——否则它将不会被识别。
57 |
58 | ### `v-else-if`
59 |
60 | > 2.1.0 新增
61 |
62 | `v-else-if`,顾名思义,充当 `v-if` 的“else-if 块”。可以链式地使用多次:
63 |
64 | ```html
65 |
66 | A
67 |
68 |
69 | B
70 |
71 |
72 | C
73 |
74 |
75 | Not A/B/C
76 |
77 | ```
78 |
79 | 类似于 `v-else`,`v-else-if` 必须紧跟在 `v-if` 或者 `v-else-if` 元素之后。
80 |
81 | ### 用 `key` 管理可复用的元素
82 |
83 | Vue 会尽可能高效地渲染元素,通常会复用已有元素而不是从头开始渲染。这么做,除了使 Vue 变得非常快之外,还有一些有用的好处。例如,如果你允许用户在不同的登录方式之间切换:
84 |
85 | ``` html
86 |
87 | Username
88 |
89 |
90 |
91 | Email
92 |
93 |
94 | ```
95 |
96 | 那么在上面的代码中切换 `loginType` 将不会清除用户已经输入的内容。因为两个模版使用了相同的元素,` ` 不会被替换掉——仅仅是替换了它的的 `placeholder`。
97 |
98 | 自己动手试一试,在输入框中输入一些文本,然后按下切换按钮:
99 |
100 | {% raw %}
101 |
114 |
127 | {% endraw %}
128 |
129 | 这样也不总是符合实际需求,所以 Vue 为你提供了一种方式来声明“这两个元素是完全独立的——不要复用它们”。只需添加一个具有唯一值的 `key` 属性即可:
130 |
131 | ``` html
132 |
133 | Username
134 |
135 |
136 |
137 | Email
138 |
139 |
140 | ```
141 |
142 | 现在,每次切换时,输入框都将被重新渲染。你自己看:
143 |
144 | {% raw %}
145 |
158 |
171 | {% endraw %}
172 |
173 | 注意, `` 元素仍然会被高效地复用,因为它们没有添加 `key` 属性。
174 |
175 | ## `v-show`
176 |
177 | 另一个用于根据条件展示元素的选项是 `v-show` 指令。用法大致一样:
178 |
179 | ``` html
180 | Hello!
181 | ```
182 |
183 | 不同的是带有 `v-show` 的元素始终会被渲染并保留在 DOM 中。`v-show` 是简单地切换元素的 CSS 属性 `display` 。
184 |
185 | 注意, `v-show` 不支持 `` 语法,也不支持 `v-else`。
186 |
187 |
188 | ## `v-if` vs `v-show`
189 |
190 | `v-if` 是“真正的”条件渲染,因为它会确保在切换过程中条件块内的事件监听器和子组件适当地被销毁和重建。
191 |
192 | `v-if` 也是**惰性的**:如果在初始渲染时条件为假,则什么也不做——直到条件第一次变为真时,才会开始渲染条件块。
193 |
194 | 相比之下, `v-show` 就简单得多——不管初始条件是什么,元素总是会被渲染,并且只是简单地基于 CSS 进行切换。
195 |
196 | 一般来说, `v-if` 有更高的切换开销,而 `v-show` 有更高的初始渲染开销。因此,如果需要非常频繁地切换,则使用 `v-show` 较好;如果在运行时条件不太可能改变,则使用 `v-if` 较好。
197 |
198 | ## v-if 与 v-for 一起使用
199 |
200 | 当 v-if 与 v-for 一起使用时,v-for 具有比 v-if 更高的优先级。
201 |
202 | 请查阅 [列表渲染指南](../guide/list.html#v-for-with-v-if) 以获取详细信息。
203 |
204 |
--------------------------------------------------------------------------------
/themes/vue/source/css/_common.styl:
--------------------------------------------------------------------------------
1 | @import "_fonts"
2 | @import "_settings"
3 | @import "_syntax"
4 |
5 | body
6 | font-family $body-font
7 | font-size $body-font-size
8 | -webkit-font-smoothing antialiased
9 | -moz-osx-font-smoothing grayscale
10 | color $medium
11 | background-color white
12 | margin 0
13 | &.docs
14 | padding-top: $header-height
15 |
16 | @media screen and (max-width: 900px)
17 | body.docs
18 | padding-top: 0
19 |
20 | a
21 | text-decoration none
22 | color $medium
23 | img
24 | border none
25 |
26 | h1, h2, h3, h4, strong
27 | font-weight 600
28 | color $dark
29 |
30 | code, pre
31 | font-family $code-font
32 | font-size $code-font-size
33 | background-color $codebg
34 | -webkit-font-smoothing initial
35 | -moz-osx-font-smoothing initial
36 |
37 | code
38 | color #e96900
39 | padding 3px 5px
40 | margin 0 2px
41 | border-radius 2px
42 | white-space nowrap
43 |
44 | em
45 | color $light
46 |
47 | p
48 | word-spacing 0.05em
49 |
50 | a.button
51 | padding 0.75em 2em
52 | border-radius 2em
53 | display inline-block
54 | color #fff
55 | background-color lighten($green, 8%)
56 | transition all .15s ease
57 | box-sizing border-box
58 | border 1px solid lighten($green, 8%)
59 | &.white
60 | background-color #fff
61 | color $green
62 | .highlight
63 | overflow-x auto
64 | position relative
65 | padding 0
66 | background-color $codebg
67 | padding .8em .8em .4em
68 | line-height 1.1em
69 | border-radius $radius
70 | table, tr, td
71 | width 100%
72 | border-collapse collapse
73 | padding 0
74 | margin 0
75 | .gutter
76 | width 1.5em
77 | .code
78 | $code-line-height = 1.5em
79 | pre
80 | padding 1.2em 1.4em
81 | line-height $code-line-height
82 | margin 0
83 | .line
84 | min-height $code-line-height
85 | &.html, &.js, &.bash, &.css
86 | .code:after
87 | position absolute
88 | top 0
89 | right 0
90 | color #ccc
91 | text-align right
92 | font-size .75em
93 | padding 5px 10px 0
94 | line-height 15px
95 | height 15px
96 | font-weight 600
97 | &.html .code:after
98 | content 'HTML'
99 | &.js .code:after
100 | content 'JS'
101 | &.bash .code:after
102 | content 'Shell'
103 | &.css .code:after
104 | content 'CSS'
105 |
106 | #main
107 | position relative
108 | z-index 1
109 | padding 0 60px 30px
110 | overflow-x hidden
111 |
112 | #ad
113 | width 125px
114 | // text-align center
115 | position fixed
116 | z-index 99
117 | bottom 10px
118 | right 10px
119 | padding 10px
120 | background-color #fff
121 | border-radius 3px
122 | font-size 13px
123 | a
124 | display inline-block
125 | color $light
126 | font-weight normal
127 | span
128 | color $light
129 | display inline-block
130 | margin-bottom 5px
131 | img
132 | width 125px
133 | .carbon-img, .carbon-text
134 | display block
135 | margin-bottom 6px
136 | font-weight normal
137 | color $medium
138 | .carbon-poweredby
139 | color #aaa
140 | font-weight normal
141 |
142 | #nav
143 | .nav-link
144 | cursor pointer
145 | .nav-dropdown-container
146 | .nav-link
147 | &:hover
148 | border-bottom none
149 | &:hover
150 | .nav-dropdown
151 | display block
152 | &.language
153 | margin-left 20px
154 | .arrow
155 | pointer-events none
156 | .nav-dropdown
157 | display none
158 | box-sizing border-box
159 | max-height "calc(100vh - %s)" % $header-height
160 | overflow-y scroll
161 | position absolute
162 | top 100%
163 | right -15px
164 | background-color #fff
165 | padding 10px 0
166 | border 1px solid #ddd
167 | border-bottom-color #ccc
168 | text-align left
169 | border-radius 4px
170 | white-space nowrap
171 | li
172 | line-height 1.8em
173 | margin 0
174 | display block
175 | > ul
176 | padding-left: 0
177 | &:first-child
178 | h4
179 | margin-top 0
180 | padding-top: 0
181 | border-top: 0
182 | a, h4
183 | padding 0 24px 0 20px
184 | h4
185 | // text-transform uppercase
186 | margin .45em 0 0
187 | padding-top: .45em
188 | border-top: 1px solid #eee
189 | a
190 | color lighten($dark, 10%)
191 | font-size .9em
192 | display block
193 | &:hover
194 | color $green
195 | .arrow
196 | display inline-block
197 | vertical-align middle
198 | margin-top -1px
199 | margin-left 6px
200 | margin-right -14px
201 | width 0
202 | height 0
203 | border-left 4px solid transparent
204 | border-right 4px solid transparent
205 | border-top 5px solid #ccc
206 |
--------------------------------------------------------------------------------
/themes/vue/source/images/vuejobs.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/src/v2/guide/events.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: 事件处理器
3 | type: guide
4 | order: 9
5 | ---
6 |
7 | ## 监听事件
8 |
9 | 可以用 `v-on` 指令监听 DOM 事件来触发一些 JavaScript 代码。
10 |
11 | 示例:
12 |
13 | ``` html
14 |
15 |
增加 1
16 |
这个按钮被点击了 {{ counter }} 次。
17 |
18 | ```
19 | ``` js
20 | var example1 = new Vue({
21 | el: '#example-1',
22 | data: {
23 | counter: 0
24 | }
25 | })
26 | ```
27 |
28 | 结果:
29 |
30 | {% raw %}
31 |
32 |
增加 1
33 |
这个按钮被点击了 {{ counter }} 次。
34 |
35 |
43 | {% endraw %}
44 |
45 | ## 方法事件处理器
46 |
47 | 许多事件处理的逻辑都很复杂,所以直接把 JavaScript 代码写在 `v-on` 指令中是不可行的。因此 `v-on` 可以接收一个定义的方法来调用。
48 |
49 | 示例:
50 |
51 | ``` html
52 |
53 |
54 | Greet
55 |
56 | ```
57 |
58 | ``` js
59 | var example2 = new Vue({
60 | el: '#example-2',
61 | data: {
62 | name: 'Vue.js'
63 | },
64 | // 在 `methods` 对象中定义方法
65 | methods: {
66 | greet: function (event) {
67 | // `this` 在方法里指当前 Vue 实例
68 | alert('Hello ' + this.name + '!')
69 | // `event` 是原生 DOM 事件
70 | alert(event.target.tagName)
71 | }
72 | }
73 | })
74 |
75 | // 也可以用 JavaScript 直接调用方法
76 | example2.greet() // -> 'Hello Vue.js!'
77 | ```
78 |
79 | 结果:
80 |
81 | {% raw %}
82 |
83 | Greet
84 |
85 |
99 | {% endraw %}
100 |
101 | ## 内联处理器方法
102 |
103 | 除了直接绑定到一个方法,也可以用内联 JavaScript 语句:
104 |
105 | ``` html
106 |
107 | Say hi
108 | Say what
109 |
110 | ```
111 | ``` js
112 | new Vue({
113 | el: '#example-3',
114 | methods: {
115 | say: function (message) {
116 | alert(message)
117 | }
118 | }
119 | })
120 | ```
121 |
122 | 结果:
123 |
124 | {% raw %}
125 |
126 | Say hi
127 | Say what
128 |
129 |
139 | {% endraw %}
140 |
141 |
142 | 有时也需要在内联语句处理器中访问原生 DOM 事件。可以用特殊变量 `$event` 把它传入方法:
143 |
144 | ``` html
145 | Submit
146 | ```
147 |
148 | ``` js
149 | // ...
150 | methods: {
151 | warn: function (message, event) {
152 | // 现在我们可以访问原生事件对象
153 | if (event) event.preventDefault()
154 | alert(message)
155 | }
156 | }
157 | ```
158 |
159 | ## 事件修饰符
160 |
161 | 在事件处理程序中调用 `event.preventDefault()` 或 `event.stopPropagation()` 是非常常见的需求。尽管我们可以在 methods 中轻松实现这点,但更好的方式是:methods 只有纯粹的数据逻辑,而不是去处理 DOM 事件细节。
162 |
163 | 为了解决这个问题, Vue.js 为 `v-on` 提供了 **事件修饰符**。通过由点(.)表示的指令后缀来调用修饰符。
164 |
165 | - `.stop`
166 | - `.prevent`
167 | - `.capture`
168 | - `.self`
169 | - `.once`
170 |
171 | ``` html
172 |
173 |
174 |
175 |
176 |
177 |
178 |
179 |
180 |
181 |
182 |
183 |
184 |
185 | ...
186 |
187 |
188 | ...
189 | ```
190 |
191 | > 2.1.4 新增
192 |
193 | ``` html
194 |
195 |
196 | ```
197 | 不像其它只能对原生的 DOM 事件起作用的修饰符,`.once` 修饰符还能被用到自定义的[组件事件](components.html#Using-v-on-with-Custom-Events)上. 如果你还没有阅读关于组件的文档,现在大可不必担心。
198 |
199 | ## 按键修饰符
200 |
201 | 在监听键盘事件时,我们经常需要监测常见的键值。 Vue 允许为 `v-on` 在监听键盘事件时添加按键修饰符:
202 |
203 | ``` html
204 |
205 |
206 | ```
207 |
208 | 记住所有的 keyCode 比较困难,所以 Vue 为最常用的按键提供了别名:
209 |
210 | ``` html
211 |
212 |
213 |
214 |
215 |
216 | ```
217 |
218 | 全部的按键别名:
219 |
220 | - `.enter`
221 | - `.tab`
222 | - `.delete` (捕获 “删除” 和 “退格” 键)
223 | - `.esc`
224 | - `.space`
225 | - `.up`
226 | - `.down`
227 | - `.left`
228 | - `.right`
229 |
230 | 可以通过全局 `config.keyCodes` 对象[自定义按键修饰符别名](../api/#keyCodes):
231 |
232 | ``` js
233 | // 可以使用 v-on:keyup.f1
234 | Vue.config.keyCodes.f1 = 112
235 | ```
236 |
237 | ## 按键修饰符
238 |
239 | > 2.1.0 新增
240 |
241 | 可以用如下修饰符开启鼠标或键盘事件监听,使在按键按下时发生响应。
242 |
243 | - `.ctrl`
244 | - `.alt`
245 | - `.shift`
246 | - `.meta`
247 |
248 | > 注意:在Mac系统键盘上,meta对应命令键 (⌘)。在Windows系统键盘meta对应windows徽标键(⊞)。在Sun操作系统键盘上,meta对应实心宝石键 (◆)。在其他特定键盘上,尤其在MIT和Lisp键盘及其后续,比如Knight键盘,space-cadet键盘,meta被标记为“META”。在Symbolics键盘上,meta被标记为“META” 或者 “Meta”。
249 | 例如:
250 |
251 | ```html
252 |
253 |
254 |
255 |
256 | Do something
257 | ```
258 |
259 | ## 为什么在 HTML 中监听事件?
260 |
261 | 你可能注意到这种事件监听的方式违背了关注点分离(separation of concern)传统理念。不必担心,因为所有的 Vue.js 事件处理方法和表达式都严格绑定在当前视图的 ViewModel 上,它不会导致任何维护上的困难。实际上,使用 `v-on` 有几个好处:
262 |
263 | 1. 扫一眼 HTML 模板便能轻松定位在 JavaScript 代码里对应的方法。
264 |
265 | 2. 因为你无须在 JavaScript 里手动绑定事件,你的 ViewModel 代码可以是非常纯粹的逻辑,和 DOM 完全解耦,更易于测试。
266 |
267 | 3. 当一个 ViewModel 被销毁时,所有的事件处理器都会自动被删除。你无须担心如何自己清理它们。
268 |
269 | ***
270 |
271 | > 原文:http://vuejs.org/guide/events.html
272 |
273 | ***
274 |
275 |
276 |
--------------------------------------------------------------------------------
/themes/vue/source/css/page.styl:
--------------------------------------------------------------------------------
1 | @import "_common"
2 | @import "_header"
3 | @import "_demo"
4 | @import "_sponsor"
5 | @import "_migration"
6 | @import "_sidebar"
7 |
8 | #header
9 | box-shadow 0 0 1px rgba(0,0,0,.25)
10 | transition background-color .3s ease-in-out
11 |
12 | .content
13 | position relative
14 | padding 2.2em 0
15 | max-width 800px
16 | margin 0 auto
17 | &.api
18 | > a:first-of-type > h2
19 | margin-top 0
20 | padding-top: 0
21 | ul
22 | padding-left 1.25em
23 | line-height 1.4em
24 | ul, p
25 | margin .6em 0
26 | a.button
27 | font-size .9em
28 | color #fff
29 | margin .2em 0
30 | width 180px
31 | text-align center
32 | padding 12px 24px
33 | display inline-block
34 | vertical-align middle
35 | img
36 | max-width 100%
37 | span.light
38 | color $light
39 | span.info
40 | font-size .85em
41 | display inline-block
42 | vertical-align middle
43 | width 280px
44 | margin-left 20px
45 | h1
46 | margin 0 0 1em
47 | h2, h3
48 | &:before
49 | content ''
50 | display block
51 | margin-top -1 * $heading-link-padding-top
52 | height $heading-link-padding-top
53 | visibility hidden
54 | h2
55 | margin $h2-margin-top 0 .8em
56 | padding-bottom .7em
57 | border-bottom 1px solid $border
58 | z-index: -1
59 | h3
60 | margin $h3-margin-top 0 1.2em
61 | position relative
62 | z-index: -1
63 | &:after
64 | content "#"
65 | color $green
66 | position absolute
67 | left -0.7em
68 | bottom -2px
69 | font-size 1.2em
70 | font-weight bold
71 | figure
72 | margin 1.2em 0
73 | p, ul, ol
74 | line-height 1.6em
75 | // HACK: Create area underneath paragraphs
76 | // and lists that will be on top of heading
77 | // anchors, for easier text highlighting.
78 | margin 1.2em 0 -1.2em
79 | padding-bottom 1.2em
80 | position relative
81 | z-index: 1
82 | ul, ol
83 | padding-left 1.5em
84 | a
85 | color $green
86 | font-weight 400
87 | blockquote
88 | margin 2em 0
89 | padding-left 20px
90 | border-left 4px solid $green
91 | p
92 | font-weight 600
93 | margin-left 0
94 | iframe
95 | margin 1em 0
96 | > table
97 | border 2px solid $white
98 | margin 1.2em auto
99 | padding: 1em
100 | td, th
101 | line-height 1.6em
102 | padding .5em 1.4em
103 | border none
104 | td
105 | background-color: lighten($codebg, 60%)
106 | th
107 | background-color: $green
108 | color: #fff
109 | padding-top: .85em
110 | padding-bottom .85em
111 | text-align left
112 | tbody
113 | code
114 | background-color #efefef
115 | p.tip
116 | padding 12px 24px 12px 30px
117 | margin 2em 0
118 | border-left 4px solid $red
119 | background-color $codebg
120 | position relative
121 | border-bottom-right-radius $radius
122 | border-top-right-radius $radius
123 |
124 | &:before
125 | position absolute
126 | top 14px
127 | left -12px
128 | background-color $red
129 | color #fff
130 | content "!"
131 | width 20px
132 | height 20px
133 | border-radius 100%
134 | text-align center
135 | line-height 20px
136 | font-weight bold
137 | font-family $logo-font
138 | font-size 14px
139 |
140 | code
141 | background-color #efefef
142 |
143 | em
144 | color $medium
145 |
146 | .guide-links
147 | margin-top 2em
148 | height 1em
149 |
150 | .footer
151 | color $light
152 | margin-top 2em
153 | padding-top 2em
154 | border-top 1px solid #e5e5e5
155 | font-size .9em
156 |
157 | #main.fix-sidebar
158 | .sidebar
159 | position fixed
160 |
161 | @media screen and (min-width: 1590px)
162 | #header
163 | background-color rgba(255,255,255,.4)
164 |
165 | @media screen and (max-width: 1500px)
166 | .content.with-sidebar
167 | margin-left 280px
168 | #ad
169 | z-index 7
170 | position relative
171 | padding 0
172 | bottom 0
173 | right 0
174 | float right
175 | padding 0 0 20px 30px
176 |
177 | @media screen and (max-width: 900px)
178 | body
179 | -webkit-text-size-adjust none
180 | font-size 14px
181 | #header
182 | display none
183 | #logo
184 | display none
185 | .nav-link
186 | padding-bottom 1px
187 | &:hover, &.current
188 | border-bottom 2px solid $green
189 | #mobile-bar
190 | display block
191 | #main
192 | padding 2em 1.4em 0
193 | .highlight pre
194 | padding 1.2em 1em
195 | .content
196 | &.with-sidebar
197 | margin auto
198 | h2, h3
199 | &:before
200 | content ''
201 | display block
202 | margin-top -1 * $mobile-heading-link-padding-top
203 | height $mobile-heading-link-padding-top
204 | visibility hidden
205 | .footer
206 | margin-left 0
207 | text-align center
208 |
209 | @media screen and (max-width: 560px)
210 | #downloads
211 | text-align center
212 | margin-bottom 25px
213 | .info
214 | margin-top 5px
215 | margin-left 0
216 | iframe
217 | margin: 0 !important
218 |
--------------------------------------------------------------------------------
/src/about/index.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: 贡献者
3 | type: about
4 | order: 0
5 | ---
6 |
7 | ## Guide 翻译贡献
8 |
9 | ### Essentials 基础
10 |
11 | 序号 | 对应文档文件名 | 中文标题 | 翻译贡献者 | 校对主要贡献者
12 | ----- | ------------- | --- | --- | --- | --- | ---
13 | 1 | installation.md | 安装 | [dingyiming](https://github.com/dingyiming) | [ATLgo](https://github.com/ATLgo) [70data](https://github.com/70data)
14 | 2 | index.md | 介绍 | [hijiangtao](https://github.com/hijiangtao) | [70data](https://github.com/70data) [ATLgo](https://github.com/ATLgo)
15 | 3 | instance.md | 实例 | [dingyiming](https://github.com/dingyiming) | [70data](https://github.com/70data) [ATLgo](https://github.com/ATLgo)
16 | 4 | syntax.md | 模板语法 | [daix6](https://github.com/daix6) | [70data](https://github.com/70data)
17 | 5 | computed.md | 计算属 性 | [dingyiming](https://github.com/dingyiming) [70data](https://github.com/70data) | [70data](https://github.com/70data)
18 | 6 | class-and-style.md | Class 与 Style 绑定 | [595074187](https://github.com/595074187) | [70data](https://github.com/70data)
19 | 7 | conditional.md | 条件渲染 | [dingyiming](https://github.com/dingyiming) | [hgcoder](https://github.com/hgcoder)
20 | 8 | list.md | 列表渲染 | [tingtien](https://github.com/tingtien) | [hgcoder](https://github.com/hgcoder)
21 | 9 | events.md | 事件处理器 | [dingyiming](https://github.com/dingyiming) | [yangzj1992](https://github.com/yangzj1992)
22 | 10 | forms.md | 表单控件绑定 | [dingyiming](https://github.com/dingyiming) | [yangzj1992](https://github.com/yangzj1992)
23 | 11 | components.md | 组件 | [ezreally](https://github.com/ezreally) | [cuiyongjian](https://github.com/cuiyongjian)
24 |
25 | ### Advanced 进阶
26 |
27 | 序号 | 对应文档文件名 | 中文标题 | 翻译贡献者 | 校对主要贡献者
28 | ----- | ------------- | --- | --- | --- | ---
29 | 12 | transitions.md | 过渡: 进入, 离开, 和 列表 | [awe](https://github.com/hilongjw) | [bhnddowinf](https://github.com/bhnddowinf) [StoneQI](https://github.com/StoneQI)
30 | 13 | transitioning-state.md | 过渡状态 | [awe](https://github.com/hilongjw) | [bhnddowinf](https://github.com/bhnddowinf)
31 | 14 | render-function.md | Render 函数 | [awe](https://github.com/hilongjw) | [bhnddowinf](https://github.com/bhnddowinf)
32 | 15 | reactivity.md | 深入响应式原理 | [veaba](https://github.com/veaba) | [yangzj1992](https://github.com/yangzj1992)
33 | 16 | custom-directive.md | 自定义指令 | [harrytospring](https://github.com/harrytospring) | [yangzj1992](https://github.com/yangzj1992)
34 | 17 | mixins.md | 混合 | [harrytospring](https://github.com/harrytospring) | [bhnddowinf](https://github.com/bhnddowinf)
35 | 18 | plugins.md | 插件 | [hgcoder](https://github.com/hgcoder) | [hgcoder](https://github.com/hgcoder)
36 | 19 | single-file-components.md | 单文件组件 | [ATLgo](https://github.com/ATLgo) | [zhouzihanntu](https://github.com/zhouzihanntu)
37 | 20 | routing.md | 路由 | [dingyiming](https://github.com/dingyiming) | [mlyknown](https://github.com/mlyknown)
38 | 21 | state-management.md | 状态管理 | [dear-lizhihua](https://github.com/dear-lizhihua) | [mlyknown](https://github.com/mlyknown)
39 | 22 | unit-testing.md | 单元测试 | [70data](https://github.com/70data) | [mlyknown](https://github.com/mlyknown)
40 | 23 | ssr.md | 服务端渲染 | [dingyiming](https://github.com/dingyiming) | [yongbolv](https://github.com/yongbolv)
41 |
42 | ### Migration 迁移
43 |
44 | 序号 | 对应文档文件名 | 中文标题 | 翻译贡献者 | 校对主要贡献者
45 | ----- | ------------- | --- | --- | --- | ---
46 | 24 | migration.md | 1.x迁移 | [harrytospring](https://github.com/harrytospring) | [yongbolv](https://github.com/yongbolv)
47 | 27 | migration-vue-router.md | vue-router 0.7.x 迁移 | [forzajuve10](https://github.com/forzajuve10) | [yizhixiaolongxia](https://github.com/yizhixiaolongxia)
48 |
49 | ### Meta 更多
50 |
51 | 序号 | 对应文档文件名 | 中文标题 | 翻译贡献者 | 校对主要贡献者
52 | ----- | ------------- | --- | --- | --- | ---
53 | 25 | comparison.md | 对比其他框架 | [yongbolv](https://github.com/yongbolv) | [yangzj1992](https://github.com/yangzj1992)
54 | 26 | join.md | 加入 Vue.js 社区 | [daix6](https://github.com/daix6) | [zhouzihanntu](https://github.com/zhouzihanntu)
55 |
56 | ## API翻译贡献
57 |
58 | 序号 | 对应小节名称 | 中文标题 | 翻译贡献者 | 校对主要贡献者
59 | ----- | ------------- | --- | --- | --- | --- | ---
60 | 1 | Global Config | 全局配置 | [dear-lizhihua](https://github.com/dear-lizhihua) | [bhnddowinf](https://github.com/bhnddowinf)
61 | 2 | Global API | 全局 API | [dear-lizhihua](https://github.com/dear-lizhihua) | [bhnddowinf](https://github.com/bhnddowinf)
62 | 3 | Options / Data | 选项 / 数据 | [dear-lizhihua](https://github.com/dear-lizhihua) | [bhnddowinf](https://github.com/bhnddowinf)
63 | 4 | Options / DOM | 选项 / DOM | [ATLgo](https://github.com/ATLgo) | [bhnddowinf](https://github.com/bhnddowinf)
64 | 5 | Options / Lifecycle Hooks | 选项 / 生命周期钩子 | [ATLgo](https://github.com/ATLgo) | [bhnddowinf](https://github.com/bhnddowinf)
65 | 6 | Options / Assets | 选项 / 资源 | [dingyiming](https://github.com/dingyiming) | [bhnddowinf](https://github.com/bhnddowinf)
66 | 7 | Options / Misc | 选项 / 杂项 | [dingyiming](https://github.com/dingyiming) | [bhnddowinf](https://github.com/bhnddowinf)
67 | 8 | Instance Properties | 实例属性 | [coolzjy](https://github.com/coolzjy) | [bhnddowinf](https://github.com/bhnddowinf)
68 | 9 | Instance Methods / Data | 实例方法 / 数据 | [dingyiming](https://github.com/dingyiming) | [bhnddowinf](https://github.com/bhnddowinf)
69 | 10 | Instance Methods / Events | 实例方法 / 事件 | [mlyknown](https://github.com/mlyknown) | [bhnddowinf](https://github.com/bhnddowinf)
70 | 11 | Instance Methods / Lifecycle | 实例方法 / 生命周期 | [mlyknown](https://github.com/mlyknown)| [bhnddowinf](https://github.com/bhnddowinf)
71 | 12 | Directives | 指令| [dingyiming](https://github.com/dingyiming) | [bhnddowinf](https://github.com/bhnddowinf)
72 | 13 | Special Attributes | 特殊元素 | [70data](https://github.com/70data) | [bhnddowinf](https://github.com/bhnddowinf)
73 | 14 | Built-In Components | 内置的组件 | [dear-lizhihua](https://github.com/dear-lizhihua) | [bhnddowinf](https://github.com/bhnddowinf)
74 | 15 | VNode Interface | VNode 接口 | [70data](https://github.com/70data) | [dear-lizhihua](https://github.com/dear-lizhihua)
75 | 16 | Server-Side Rendering | 服务端渲染| [70data](https://github.com/70data) | [dear-lizhihua](https://github.com/dear-lizhihua)
76 |
77 | ## 示例翻译
78 |
79 | 翻译贡献者 : [lindazhang102](https://github.com/lindazhang102)
80 |
81 |
82 | ## 感谢所有参与翻译的朋友们!
83 |
--------------------------------------------------------------------------------
/src/_posts/announcing-2.0.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Announcing Vue.js 2.0
3 | date: 2016-04-27 13:33:00
4 | ---
5 |
6 | Today I am thrilled to announce the first public preview of Vue.js 2.0, which brings along many exciting improvements and new features. Let's take a peek at what's in store!
7 |
8 |
9 |
10 | ## Even Leaner, Even Faster
11 |
12 | Vue.js has always focused on staying light and fast, but 2.0 pushes it even further. The rendering layer is now based on a lightweight virtual-DOM implementation (based on [Snabbdom](https://github.com/paldepind/snabbdom)) that improves initial rendering speed and memory consumption by up to 2~4x in most scenarios (check out [these benchmarks](https://github.com/vuejs/vue/tree/next/benchmarks)). The template-to-virtual-DOM compiler and the runtime can be separated, so you can pre-compile templates and ship your app with only the runtime, which is less than 12kb min+gzip (as a reference, React 15 is 44kb min+gzip). The compiler also works in the browser, which means you can still drop in one script tag and start hacking, just like before. Even with the compiler included, the build is sitting at 17kb min+gzip, still lighter than the current 1.0 build.
13 |
14 | ## Not Your Average Virtual-DOM
15 |
16 | Now, just virtual-DOM sounds boring because there are so many implementations out there - but this one is different. Combined with Vue's reactivity system, it provides optimized re-rendering out of the box without you having to do anything. Each component keeps track of its reactive dependencies during its render, so the system knows precisely when to re-render, and which components to re-render. No need for `shouldComponentUpdate` or immutable data structures - **it just works**.
17 |
18 | In addition, Vue 2.0 applies some advanced optimizations during the template-to-virtual-DOM compilation phase:
19 |
20 | 1. It detects static class names and attributes so that they are never diffed after the initial render.
21 |
22 | 2. It detects the maximum static sub trees (sub trees with no dynamic bindings) and hoist them out of the render function. So on each re-render, it directly reuses the exact same virtual nodes and skips the diffing.
23 |
24 | These advanced optimizations can usually only be achieved via Babel plugins when using JSX, but with Vue 2.0 you can get them even using the in-browser compiler.
25 |
26 | The new rendering system also allows you to disable reactive conversions by simply freezing your data and manually force updates, essentially giving you full control over the re-rendering process.
27 |
28 | With these techniques combined, Vue 2.0 ensures blazing fast performance in every possible scenario while requiring minimal optimization efforts from the developer.
29 |
30 | ## Templates, JSX, or Hyperscript?
31 |
32 | Developers tend to have strong opinions on templates vs. JSX. On the one hand, templates are closer to HTML - they map better to the semantic structure of your app and make it much easier to think visually about the design, layout and styling. On the other hand, templates are limited to the DSL while the programmatic nature of JSX/hyperscript provides the full expressive power of a turing-complete language.
33 |
34 | Being a designer/developer hybrid, I prefer writing most of my interfaces in templates, but in certain cases I do miss the flexibility of JSX/hyperscript. An example would be writing a component that programmatically handles its children, something not feasible with just the template-based slot mechanism.
35 |
36 | Well, why not have both? In Vue 2.0, you can keep using the familiar template syntax, or drop down to the virtual-DOM layer whenever you feel constrained by the template DSL. Instead of the `template` option, just replace it with a `render` function. You can even embed render functions in your templates using the special `` tag! The best of both worlds, in the same framework.
37 |
38 | ## Streaming Server-side Rendering
39 |
40 | With the migration to virtual-DOM, Vue 2.0 naturally supports server-side rendering with client-side hydration. One pain point of current mainstream server rendering implementations, such as React's, is that the rendering is synchronous so it can block the server's event loop if the app is complex. Synchronous server-side rendering may even adversely affect time-to-content on the client. Vue 2.0 provides built-in streaming server-side rendering, so that you can render your component, get a readable stream back and directly pipe it to the HTTP response. This ensures your server is responsive, and gets the rendered content to your users faster.
41 |
42 | ## Unlocking More Possibilities
43 |
44 | With the new architecture, there are even more possibilities to explore - for example, rendering to native interfaces on mobile. Currently, we are exploring a port of Vue.js 2.0 that uses [weex](http://alibaba.github.io/weex/) as a native rendering backend, a project maintained by engineers at Alibaba Group, the biggest tech enterprise of China. It is also technically feasible to adapt Vue 2.0's virtual-DOM to run inside ReactNative. We are excited to see how it goes!
45 |
46 | ## Compatibility and What to Expect Next
47 |
48 | Vue.js 2.0 is still in pre-alpha, but you can checkout the source code [here](https://github.com/vuejs/vue/tree/next/). Despite being a full rewrite, the API is largely compatible with 1.0 with the exception of some intentional deprecations. Check out [the same official examples written in 2.0](https://github.com/vuejs/vue/tree/next/examples) - you will see that not much has changed!
49 |
50 | The feature deprecations are part of our continued effort to provide the simplest API possible for maximum developer productivity. You can check out a 1.0 vs. 2.0 feature comparison [here](https://github.com/vuejs/vue/wiki/2.0-features). This does mean that it will take some effort to migrate an existing app if you happen to use some of these deprecated features heavily, but we will provide detailed upgrade guides in the future.
51 |
52 | There is still much work left to be done. We will be releasing the first alpha once we reach satisfactory test coverage, and we are aiming for beta by end of May / early June. In addition to more tests, we also need to update the supporting libraries (vue-router, Vuex, vue-loader, vueify...). Currently only Vuex works with 2.0 out of the box, but we will make sure that everything works smoothly together when 2.0 ships.
53 |
54 | We are also not forgetting about 1.x! 1.1 will be released alongside 2.0 beta, with an LTS period of 6-month critical bug fixes and 9-month security updates. It will also ship with optional deprecation warnings to get you prepared for upgrading to 2.0. Stay tuned!
55 |
--------------------------------------------------------------------------------
/src/_posts/012-release.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Vue.js 0.12 released!
3 | date: 2015-06-11 17:37:30
4 | ---
5 |
6 | I'm really excited to announce that [Vue.js 0.12: Dragon Ball](https://github.com/yyx990803/vue/releases/tag/0.12.0) is finally here! Thanks to everyone who tried out the beta/rc versions and provided feedback / bug reports along the way.
7 |
8 | There's a lot to cover in this release, and we will talk about a few highlights below. However, it is still recommended to carefully go through the [Full Release Note](https://github.com/yyx990803/vue/releases/tag/0.12.0) and updated docs if you are upgrading from 0.11. You can report bugs on GitHub, send questions to [vuejs/Discussion](https://github.com/vuejs/Discussion/issues), or join us in the [Gitter chat channel](https://gitter.im/yyx990803/vue).
9 |
10 |
11 |
12 | ### More Consistent Component Syntax
13 |
14 | Previously in 0.11 you have two ways to use a Vue.js component: using the `v-component` directive, or using custom elements. There are also two ways to pass data down to child components: using the `v-with` directive, or using the `paramAttributes` option. Although both custom elements and param attributes get compiled down to directives eventually, it is confusing and redundant to have two sets of syntax for the same functionality.
15 |
16 | In addition, it should be noted that the component system is a first-class concept in Vue.js, even more important than directives. It defines how we encapsulate our higher-level view logic and compose our application. In the meanwhile, having a clear and declarative way to pass data into child components is also very important. Components and param attributes really deserve their own dedicated syntax to differentiate from other directives.
17 |
18 | As a result, `v-component` and `v-with` have been deprecated in 0.12. `paramAttributes` has also been renamed to `props`, which is shorter and cleaner. From now on, most Vue.js components will look like this:
19 |
20 | ``` html
21 |
22 | ```
23 |
24 | There are also additional props-related improvements such as explicit one-time or one-way props, expression as props, methods as prop callbacks and more. You can find out more details in the 0.12 release notes linked above and the updated [Component System](/guide/components.html) section of the guide.
25 |
26 | ### Filter Arguments Improvements
27 |
28 | In 0.11, filters always receive their arguments as plain strings. An argument can be enclosed in quotes to include whitespace, but the quotes are not automatically stripped when passed into the filter function. Some users were also confused about how to retrive a dynamic value on the vm instead of a plain string.
29 |
30 | In 0.12, the filter argument syntax now follows a simple rule: if an argument is enclosed in quotes, it will be passed in as a plain string; otherwise, it will be evaluated against the current vm as a dynamic value.
31 |
32 | This means the usage of some existing filters will have to change:
33 |
34 | ``` html
35 |
36 | {{ items.length | pluralize 'item' }}
37 | ```
38 |
39 | But it would make custom filters that rely on dynamic values much easier to write:
40 |
41 | ``` html
42 | {{ msg | concat otherMsg }}
43 | ```
44 |
45 | Here the first argument to the `concat` filter will be the value of `this.otherMsg`.
46 |
47 | ### Asynchronous Components
48 |
49 | It is common practice to bundle all the JavaScript into one file when building large single page applications. But when the file becomes too large, we may want to defer loading parts of our application for a faster initial load. However, this does pose some constraints on how the application architecture should be designed. It could be very tricky to figure out how to properly split up your JavaScript bundles.
50 |
51 | Well, with Vue.js we can already build our applications as decoupled components. If we can lazily load a dynamic component only when it is needed, wouldn't it be awesome? As a matter of fact, in 0.12 this would be trivially easy with the new Asynchronous Component feature.
52 |
53 | In 0.12, you can define a component as a factory function that asynchronously resolves a component definition (can be just a plain options object). Vue.js will only trigger the factory function when the component actually needs to be rendered, and will cache the result for future re-renders:
54 |
55 | ``` js
56 | Vue.component('async-example', function (resolve, reject) {
57 | setTimeout(function () {
58 | resolve({
59 | template: 'I am async!
'
60 | })
61 | }, 1000)
62 | })
63 | ```
64 |
65 | It is up to you to decide how to load the component from the server, e.g. `$.getScript()` or require.js; but the recommended usage is to pair it up with Webpack's [Code Splitting feature](http://webpack.github.io/docs/code-splitting.html):
66 |
67 | ``` js
68 | Vue.component('async-webpack-example', function (resolve, reject) {
69 | // In Webpack AMD like syntax indicates a code split point
70 | require(['./my-async-component'], resolve)
71 | })
72 | ```
73 |
74 | That's all you need to do. You can use the component just like before, without even thinking about it being async. Webpack will automatically split your final JavaScript into separate bundles with correct dependencies, and automatically load a bundle via Ajax when it is required. You can check out a fully functional example [here](https://github.com/vuejs/vue-webpack-example).
75 |
76 | ### Improved Transition System
77 |
78 | Vue.js' transition system is really easy to use, but in the past it has the limitation that you cannot mix CSS and JavaScript-based transitions together. In 0.12 that is no longer the case! The improved transition system now allows you to add JavaScript hooks to a CSS-based transition for additional control. The amount of hooks exposed have also been expanded to give you finer-grained control at every stage of the transition.
79 |
80 | `v-repeat` now also ships with built-in support for staggering transitions. It is as simple as adding `stagger="100"` to your repeated element. It is also possible to define separate staggering for enter and leaving, or even dynamically calculate the staggering delay in a JavaScript hook.
81 |
82 | For full details on the new transition system, check out the [updated guide](/guide/transitions.html).
83 |
84 | ### Performance Tuning
85 |
86 | Vue.js' precise dependency tracking makes it the one of the most efficient view layer for small hot updates, but there's always room for improvement. In 0.12, internal instance creation and compilation refactors have improved first-render performance for large lists by up to 40%. With proper `track-by` usage, [re-rendering with large, brand new dataset](http://vuejs.github.io/js-repaint-perfs/vue/) is also comparable to, or even faster than other Virtual-DOM based frameworks.
87 |
88 | ### One More Thing...
89 |
90 | With 0.12 out of the door, more efforts will now be spent on the official vue-router, a dedicated routing library for Vue.js with nested view matching, full transition support, and asynchronous data hooks. I have expressed that Vue.js core intends to stay as a no-frills, drop-in view layer library, and that will not change. The vue-router will be shipped separately and is totally optional, however you can expect it to work seamlessly with Vue.js core when you need it.
91 |
--------------------------------------------------------------------------------
/src/v2/cookbook/adding-instance-properties.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Adding Instance Properties
3 | type: cookbook
4 | order: 1.1
5 | ---
6 |
7 | ## Simple Example
8 |
9 | There may be data/utilities you'd like to use in many components, but you don't want to [pollute the global scope](https://github.com/getify/You-Dont-Know-JS/blob/master/scope%20%26%20closures/ch3.md). In these cases, you can make them available to each Vue instance by defining them on the prototype:
10 |
11 | ``` js
12 | Vue.prototype.$appName = 'My App'
13 | ```
14 |
15 | Now `$appName` is available on all Vue instances, even before creation. If we run:
16 |
17 | ``` js
18 | new Vue({
19 | beforeCreate: function () {
20 | console.log(this.$appName)
21 | }
22 | })
23 | ```
24 |
25 | Then `"My App"` will be logged to the console. It's that simple!
26 |
27 | ## The Importance of Scoping Instance Properties
28 |
29 | You may be wondering:
30 |
31 | > "Why does `appName` start with `$`? Is that important? What does it do?
32 |
33 | No magic is happening here. `$` is simply a convention Vue uses for properties that are available to all instances. This avoids conflicts with any defined data, computed properties, or methods.
34 |
35 | > "Conflicts? What do you mean?"
36 |
37 | Another great question! If you just set:
38 |
39 | ``` js
40 | Vue.prototype.appName = 'My App'
41 | ```
42 |
43 | Then what would you expect to be logged below?
44 |
45 | ``` js
46 | new Vue({
47 | data: {
48 | // Uh oh - appName is *also* the name of the
49 | // instance property we just defined!
50 | appName: 'The name of some other app'
51 | },
52 | beforeCreate: function () {
53 | console.log(this.appName)
54 | },
55 | created: function () {
56 | console.log(this.appName)
57 | }
58 | })
59 | ```
60 |
61 | It would be `"The name of some other app"`, then `"My App"`, because `this.appName` is overwritten ([sort of](https://github.com/getify/You-Dont-Know-JS/blob/master/this%20%26%20object%20prototypes/ch5.md)) by `data` when the instance is created. We scope instance properties with `$` to avoid this. You can even use your own convention if you'd like, such as `$_appName` or `ΩappName`, to prevent even conflicts with plugins or future features.
62 |
63 | ## Real-World Example: Replacing Vue Resource with Axios
64 |
65 | Let's say you're replacing the [now-retired Vue Resource](https://medium.com/the-vue-point/retiring-vue-resource-871a82880af4). You really enjoyed accessing request methods through `this.$http` and you want to do the same thing with Axios instead.
66 |
67 | All you have to do is include axios in your project:
68 |
69 | ``` html
70 |
71 |
72 |
73 |
74 | {{ user.name }}
75 |
76 |
77 | ```
78 |
79 | Alias `axios` to `Vue.prototype.$http`:
80 |
81 | ``` js
82 | Vue.prototype.$http = axios
83 | ```
84 |
85 | Then you'll be able to use methods like `this.$http.get` in any Vue instance:
86 |
87 | ``` js
88 | new Vue({
89 | el: '#app',
90 | data: {
91 | users: []
92 | },
93 | created () {
94 | var vm = this
95 | this.$http.get('https://jsonplaceholder.typicode.com/users')
96 | .then(function (response) {
97 | vm.users = response.data
98 | })
99 | }
100 | })
101 | ```
102 |
103 | ## The Context of Prototype Methods
104 |
105 | In case you're not aware, methods added to a prototype in JavaScript gain the context of the instance. That means they can use `this` to access data, computed properties, methods, or anything else defined on the instance.
106 |
107 | Let's take advantage of this in a `$reverseText` method:
108 |
109 | ``` js
110 | Vue.prototype.$reverseText = function (propertyName) {
111 | this[propertyName] = this[propertyName].split('').reverse().join('')
112 | }
113 |
114 | new Vue({
115 | data: {
116 | message: 'Hello '
117 | },
118 | created: function () {
119 | console.log(this.message) // => "Hello"
120 | this.$reverseText('message')
121 | console.log(this.message) // => "olleH"
122 | }
123 | })
124 | ```
125 |
126 | Note that the context binding will __not__ work if you use an ES6/2015 arrow function, as they implicitly bind to their parent scope. That means the arrow function version:
127 |
128 | ``` js
129 | Vue.prototype.$reverseText = propertyName => {
130 | this[propertyName] = this[propertyName].split('').reverse().join('')
131 | }
132 | ```
133 |
134 | Would throw an error:
135 |
136 | ``` log
137 | Uncaught TypeError: Cannot read property 'split' of undefined
138 | ```
139 |
140 | ## When To Avoid This Pattern
141 |
142 | As long as you're vigilant in scoping prototype properties, using this pattern is quite safe - as in, unlikely to produce bugs.
143 |
144 | However, it can sometimes cause confusion with other developers. They might see `this.$http`, for example, and think, "Oh, I didn't know about this Vue feature!" Then they move to a different project and are confused when `this.$http` is undefined. Or, maybe they want to Google how to do something, but can't find results because they don't realize they're actually using Axios under an alias.
145 |
146 | __The convenience comes at the cost of explicitness.__ When just looking at a component, it's impossible to tell where `$http` came from. Vue itself? A plugin? A coworker?
147 |
148 | So what are the alternatives?
149 |
150 | ## Alternative Patterns
151 |
152 | ### When Not Using a Module System
153 |
154 | In applications with __no__ module system (e.g. via Webpack or Browserify), there's a pattern that's often used with _any_ JavaScript-enhanced frontend: a global `App` object.
155 |
156 | If what you want to add has nothing to do with Vue specifically, this may be a good alternative to reach for. Here's an example:
157 |
158 | ``` js
159 | var App = Object.freeze({
160 | name: 'My App',
161 | description: '2.1.4',
162 | helpers: {
163 | // This is a purely functional version of
164 | // the $reverseText method we saw earlier
165 | reverseText: function (text) {
166 | return text.split('').reverse().join('')
167 | }
168 | }
169 | })
170 | ```
171 |
172 | If you raised an eyebrow at `Object.freeze`, what it does is prevent the object from being changed in the future. This essentially makes all its properties constants, protecting you from future state bugs.
173 |
174 | Now the source of these shared properties is much more obvious: there's an `App` object defined somewhere in the app. To find it, developers need only run a project-wide search.
175 |
176 | Another advantage is that `App` can now be used _anywhere_ in your code, whether it's Vue-related or not. That includes attaching values directly to instance options, rather than having to enter a function to access properties on `this`:
177 |
178 | ``` js
179 | new Vue({
180 | data: {
181 | appVersion: App.version
182 | },
183 | methods: {
184 | reverseText: App.helpers.reverseText
185 | }
186 | })
187 | ```
188 |
189 | ### When Using a Module System
190 |
191 | When you have access to a module system, you can easily organize shared code into modules, then `require`/`import` those modules wherever they're needed. This is the epitome of explicitness, because in each file you gain a list of dependencies. You know _exactly_ each one came from.
192 |
193 | While certainly more verbose, this approach is definitely the most maintainable, especially when working with other developers and/or building a large app.
194 |
--------------------------------------------------------------------------------