diff --git a/_config.yml b/_config.yml index 49309d00e..1e5654f7e 100644 --- a/_config.yml +++ b/_config.yml @@ -1,6 +1,6 @@ # Hexo Configuration -## Docs: http://zespia.tw/hexo/docs/configuration.html -## Source: https://github.com/tommy351/hexo/ +## Docs: https://hexo.io/docs/ +## Source: https://github.com/hexojs/hexo # Site title: Vue.js @@ -78,8 +78,8 @@ pagination_dir: page disqus_shortname: # Extensions -## Plugins: https://github.com/tommy351/hexo/wiki/Plugins -## Themes: https://github.com/tommy351/hexo/wiki/Themes +## Plugins: https://github.com/hexojs/hexo/wiki/Plugins +## Themes: https://github.com/hexojs/hexo/wiki/Themes theme: vue exclude_generator: @@ -136,7 +136,7 @@ offline: origin: maxcdn.bootstrapcdn.com # Deployment -## Docs: http://zespia.tw/hexo/docs/deployment.html +## Docs: https://hexo.io/docs/one-command-deployment deploy: type: git repository: git@github.com:vuejs/cn.vuejs.org.git diff --git a/src/resources/partners.md b/src/resources/partners.md new file mode 100644 index 000000000..2dfc5f711 --- /dev/null +++ b/src/resources/partners.md @@ -0,0 +1,87 @@ +--- +type: partners +partners: true +title: Vue Partners +proficiencies_urls: + VueJs: https://vuejs.org + Laravel: https://laravel.com + Node: https://nodejs.org +partners_list: + - + name: Vehikl + logo: vehikl.png + description: + Vehikl is a software consultancy specialising in PHP and JavaScript. We build best-in-class web applications written with popular frameworks such as Laravel, Express, NestJS, Vue, and React. Think of us as an extension of your team. + proficiencies: + - VueJs + - Laravel + - Node + - Team Augmentation + location: Ontario, Canada + languages: + - English + url_text: www.vehikl.com + url_link: www.vehikl.com?utm_source=vue_partners_page + hire_url: www.vehikl.com/contact/?utm_source=vue_partners_page + email: go+partner@vehikl.com + social_links: + - + name: Github + class: github + url: 'https://github.com/vehikl' + - + name: Twitter + class: twitter + url: 'https://twitter.com/vehikl' + - + name: Instagram + class: instagram + url: 'https://www.instagram.com/vehiklteam/' + + - + name: Modus Create + logo: https://res.cloudinary.com/modus-labs/image/upload/v1533109874/modus/logo-vertical-black.svg + description: + "Modus Create is a digital product agency that supports clients with business and product strategy consulting, customer experience, cloud services, and Agile software delivery. Our official partnerships with Atlassian, AWS, InVision, Cloudflare, GitHub, Ionic Framework, and Vue.js reinforce our proven results with digital transformation with organizations from startups to the Fortune 100." + proficiencies: + - VueJs + - name: AWS + url: https://moduscreate.com/partners/aws/?utm_source=Vue&utm_medium=Partner-Page&utm_campaign=Vue_partnerpage + - name: Atlassian + url: https://moduscreate.com/partners/atlassian/?utm_source=Vue&utm_medium=Partner-Page&utm_campaign=Vue_partnerpage + - name: Ionic + url: https://moduscreate.com/partners/ionic/?utm_source=Vue&utm_medium=Partner-Page&utm_campaign=Vue_partnerpage + - name: Product Management + url: https://moduscreate.com/what-we-do/product-management/?utm_source=Vue&utm_medium=Partner-Page&utm_campaign=Vue_partnerpage + - name: Customer Experience + url: https://moduscreate.com/what-we-do/customer-experience/?utm_source=Vue&utm_medium=Partner-Page&utm_campaign=Vue_partnerpage + - name: Agile Transformation + url: https://moduscreate.com/what-we-do/agile-transformation/?utm_source=Vue&utm_medium=Partner-Page&utm_campaign=Vue_partnerpage + - name: Cloud Migration + url: https://moduscreate.com/what-we-do/cloud-migration/?utm_source=Vue&utm_medium=Partner-Page&utm_campaign=Vue_partnerpage + location: Reston, VA, USA / Los Angeles, CA, USA / Cluj, Romania / San José, Costa Rica + languages: + - English + - Global + url_text: moduscreate.com + url_link: moduscreate.com/?utm_source=Vue&utm_medium=Partner-Page&utm_campaign=Vue_partnerpage + hire_url: moduscreate.com/?utm_source=Vue&utm_medium=Partner-Page&utm_campaign=Vue_partnerpage + email: contact@moduscreate.com + social_links: + - + name: Github + class: github + url: 'https://github.com/ModusCreateOrg' + - + name: Twitter + class: twitter + url: 'https://twitter.com/ModusCreate' + - + name: LinkedIn + class: linkedin + url: 'https://www.linkedin.com/company/modus-create-inc' + - + name: YouTube + class: youtube + url: 'https://www.youtube.com/moduscreate' +--- diff --git a/src/resources/themes.md b/src/resources/themes.md new file mode 100644 index 000000000..c46e8c8f2 --- /dev/null +++ b/src/resources/themes.md @@ -0,0 +1,69 @@ +--- +title: Themes +type: resources +order: 804 +--- +{% raw %} +
+
+ +
+ +

+ Want to feature your themes here? + Contact us! +

+
+ + + + +{% endraw %} diff --git a/src/support-vuejs/index.md b/src/support-vuejs/index.md index e010c9081..679571bc4 100644 --- a/src/support-vuejs/index.md +++ b/src/support-vuejs/index.md @@ -1,3 +1,4 @@ --- sponsors: true +type: sponsors --- diff --git a/src/v2/cookbook/form-validation.md b/src/v2/cookbook/form-validation.md index 15c7a75fe..ea17b37a3 100644 --- a/src/v2/cookbook/form-validation.md +++ b/src/v2/cookbook/form-validation.md @@ -1,432 +1,432 @@ ---- -title: 表单校验 -type: cookbook -order: 3 ---- - -## 基本的示例 - -
Watch a free lesson on Vue School
- -表单校验是浏览器原生支持的,但是有的时候用不同的浏览器处理起来需要一些小技巧。即使当表单校验已经被完美支持,你也还是有很多时候需要进行自定义的校验。这时一个更加手动的基于 Vue 的解决方案可能会更适合。我们来看一个简单的示例。 - -给定一个表单,包含三个字段,其中两个是必填项。我们先来看看 HTML: - -``` html -
- -

- Please correct the following error(s): -

-

- -

- - -

- -

- - -

- -

- - -

- -

- -

- -
-``` - -我们从头到尾看一遍,这个 `
` 标记上有一个我们将会用在 Vue 组件上的 ID。这里有一个你稍后会看到的 `submit` 处理函数,而这里的 `action` 是一个可能指向了某个真实服务器的临时 URL (当然你在服务端也是要有校验的)。 - -下面有一段内容,会根据错误状态进行显示或隐藏。它将会在表单的最顶端渲染一个简单的错误列表。同时要注意我们会在提交的时候进行校验,而不是每个字段被修改的时候。 - -最后值得注意的是这三个字段都有一个对应的 `v-model` 来连接它们的值,我们将会在 JavaScript 中使用它。现在我们就来看一下。 - -``` js -const app = new Vue({ - el: '#app', - data: { - errors: [], - name: null, - age: null, - movie: null - }, - methods:{ - checkForm: function (e) { - if (this.name && this.age) { - return true; - } - - this.errors = []; - - if (!this.name) { - this.errors.push('Name required.'); - } - if (!this.age) { - this.errors.push('Age required.'); - } - - e.preventDefault(); - } - } -}) -``` - -非常短小精悍。我们定义了一个数组来放置错误,并将这三个表单字段的默认值设为 `null`。`checkForm` 的逻辑 (在表单提交时运行) 只会检查姓名和年龄,因为电影是选填的。如果它们是空的,那么我们会检查每一个字段并设置相应的错误,差不多就是这样。你可以在下面运行这个 demo。不要忘记提交成功时它会 POST 到一个临时的 URL。 - -

CodePen 查看 Raymond Camden (@cfjedimaster) 的 表单校验 1

- - -## 使用自定义校验 - -对于第二个示例来说,第二个文本字段 (年龄) 变换成了电子邮件地址,它将会通过一些自定义的逻辑来校验。这部分代码来自 StackOverflow 的问题:[如何在 JavaScript 中校验电子邮件地址](https://stackoverflow.com/questions/46155/how-to-validate-email-address-in-javascript)。这是一个很好的问题,因为它会让 Facebook 上最激烈的政治、宗教争论看上去都只是“哪家的啤酒最好喝”这样的小分歧了。讲真的这很疯狂。我们来看 HTML,尽管它和第一个例子很接近。 - -``` html - - -

- Please correct the following error(s): -

-

- -

- - -

- -

- - -

- -

- - -

- -

- -

- -
-``` - -尽管这里的不同点很小,注意顶端的 `novalidate="true"`。但是这很重要,因为浏览器会尝试在 `type="email"` 的字段校验邮件地址。坦白说在这个案例中浏览器的校验规则是值得信任的,不过我们想要创建一个自定义校验的例子,所以把它禁用了。以下是更新后的 JavaScript。 - -``` js -const app = new Vue({ - el: '#app', - data: { - errors: [], - name: null, - email: null, - movie: null - }, - methods: { - checkForm: function (e) { - this.errors = []; - - if (!this.name) { - this.errors.push("Name required."); - } - if (!this.email) { - this.errors.push('Email required.'); - } else if (!this.validEmail(this.email)) { - this.errors.push('Valid email required.'); - } - - if (!this.errors.length) { - return true; - } - - e.preventDefault(); - }, - validEmail: function (email) { - var re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; - return re.test(email); - } - } -}) -``` - -如你所见,我们添加了一个新方法 `validEmail`,它将会在 `checkForm` 中被调用了。我们现在可以这样运行示例: - -

CodePen 查看 Raymond Camden (@cfjedimaster) 的 表单校验 2

- - -## 另一个自定义校验的例子 - -在第三个示例中,我们已经构建了一些你可能在一些调研类应用中见过的东西。用户需要花掉“预算”来为歼星舰模型装配一套部件。总价必须等于 100。先看 HTML。 - -``` html -
- -

- Please correct the following error(s): -

-

- -

- Given a budget of 100 dollars, indicate how much - you would spend on the following features for the - next generation Star Destroyer. Your total must sum up to 100. -

- -

- Weapons
- Shields
- Coffee
- Air Conditioning
- Mouse Droids
-

- -

- Current Total: {{total}} -

- -

- -

- -
-``` - -这组输入框覆盖了五个不同的部件。注意这里为 `v-model` 特性添加了 `.number`。它会告诉 Vue 将其值作为数字来使用。不过这里有一个小小的 bug,那就是当其值为空的时候,它会回到字符串格式,稍后你将会看到变通的办法。为了让用户使用起来更方便,我们添加展示了一个当前的总和,这样我们就能够实时的看到它们一共花掉了多少钱。现在我们来看看 JavaScript。 - -``` js -const app = new Vue({ - el: '#app', - data:{ - errors: [], - weapons: 0, - shields: 0, - coffee: 0, - ac: 0, - mousedroids: 0 - }, - computed: { - total: function () { - // 必须解析,因为 Vue 会将空值转换为字符串 - return Number(this.weapons) + - Number(this.shields) + - Number(this.coffee) + - Number(this.ac+this.mousedroids); - } - }, - methods:{ - checkForm: function (e) { - this.errors = []; - - if (this.total != 100) { - this.errors.push('Total must be 100!'); - } - - if (!this.errors.length) { - return true; - } - - e.preventDefault(); - } - } -}) -``` - -我们将总和设置为了一个计算属性,从那个我们解决掉的 bug 外面看上去,这已经足够了。我的 `checkForm` 方法现在只需要关注总和是不是 100 了。你可以在这里试用: - -

CodePen 查看 Raymond Camden (@cfjedimaster) 的 表单校验3

- - -## 服务端校验 - -在我们最终的示例中,我们构建了一些用到 Ajax 的服务端校验的东西。这个表单将会问你为一个新产品起名字,并且将会确保这个名字是唯一的。我们快速写了一个 [OpenWhisk](http://openwhisk.apache.org/) 的 serverless action 来进行这个校验。虽然这不是非常重要,但其逻辑如下: - -``` js -function main(args) { - return new Promise((resolve, reject) => { - // 不好的产品名:vista, empire, mbp - const badNames = ['vista', 'empire', 'mbp']; - - if (badNames.includes(args.name)) { - reject({error: 'Existing product'}); - } - - resolve({status: 'ok'}); - }); -} -``` - -基本上除了“vista”、“empire”和“mbp”的名字都是可以接受的。好,让我们来看看表单。 - -``` html -
- -

- Please correct the following error(s): -

-

- -

- - -

- -

- -

- -
-``` - -这里没有任何特殊的东西。接下来我们再看看 JavaScript。 - -``` js -const apiUrl = 'https://openwhisk.ng.bluemix.net/api/v1/web/rcamden%40us.ibm.com_My%20Space/safeToDelete/productName.json?name='; - -const app = new Vue({ - el: '#app', - data: { - errors: [], - name: '' - }, - methods:{ - checkForm: function (e) { - e.preventDefault(); - - this.errors = []; - - if (this.name === '') { - this.errors.push('Product name is required.'); - } else { - fetch(apiUrl + encodeURIComponent(this.name)) - .then(res => res.json()) - .then(res => { - if (res.error) { - this.errors.push(res.error); - } else { - // 在成功的时候重定向到一个新的 URL 或做一些别的事情 - alert('ok!'); - } - }); - } - } - } -}) -``` - -我们从一个运行在 OpenWhisk 的 API 的 URL 变量开始。现在注意 `checkForm`。在这个版本中,我们始终阻止了表单的提交 (当然,它也可以通过 Vue 在 HTML 中完成)。你可以看到一个基本的校验,即 `this.name` 是否为空,然后我们请求这个 API。如果名字是无效的,我们就添加一个错误。如果是有效的,我们就不做任何事 (只是一个 alert),但是你可以引导用户去一个新页面,在 URL 中带上产品的名字,或者其它行为。接下来你可以体验这个 demo: - -

CodePen 查看 Raymond Camden (@cfjedimaster) 的 表单校验4。

- - -## 其它替代模式 - -这份秘笈专注在“手动”校验表单,当然一些非常棒的 Vue 的库会为你搞定这些事情。使用一些预打包的库可能会影响你的应用最终的体积,但是好处是非常多的。这里有经过充分测试且保持日常更新的代码。其中包括以下 Vue 的表单校验库: - -* [vuelidate](https://github.com/monterail/vuelidate) -* [VeeValidate](https://logaretm.github.io/vee-validate/) +--- +title: 表单校验 +type: cookbook +order: 3 +--- + +## 基本的示例 + +
Watch a free lesson on Vue School
+ +表单校验是浏览器原生支持的,但是有的时候用不同的浏览器处理起来需要一些小技巧。即使当表单校验已经被完美支持,你也还是有很多时候需要进行自定义的校验。这时一个更加手动的基于 Vue 的解决方案可能会更适合。我们来看一个简单的示例。 + +给定一个表单,包含三个字段,其中两个是必填项。我们先来看看 HTML: + +``` html +
+ +

+ Please correct the following error(s): +

+

+ +

+ + +

+ +

+ + +

+ +

+ + +

+ +

+ +

+ +
+``` + +我们从头到尾看一遍,这个 `
` 标记上有一个我们将会用在 Vue 组件上的 ID。这里有一个你稍后会看到的 `submit` 处理函数,而这里的 `action` 是一个可能指向了某个真实服务器的临时 URL (当然你在服务端也是要有校验的)。 + +下面有一段内容,会根据错误状态进行显示或隐藏。它将会在表单的最顶端渲染一个简单的错误列表。同时要注意我们会在提交的时候进行校验,而不是每个字段被修改的时候。 + +最后值得注意的是这三个字段都有一个对应的 `v-model` 来连接它们的值,我们将会在 JavaScript 中使用它。现在我们就来看一下。 + +``` js +const app = new Vue({ + el: '#app', + data: { + errors: [], + name: null, + age: null, + movie: null + }, + methods:{ + checkForm: function (e) { + if (this.name && this.age) { + return true; + } + + this.errors = []; + + if (!this.name) { + this.errors.push('Name required.'); + } + if (!this.age) { + this.errors.push('Age required.'); + } + + e.preventDefault(); + } + } +}) +``` + +非常短小精悍。我们定义了一个数组来放置错误,并将这三个表单字段的默认值设为 `null`。`checkForm` 的逻辑 (在表单提交时运行) 只会检查姓名和年龄,因为电影是选填的。如果它们是空的,那么我们会检查每一个字段并设置相应的错误,差不多就是这样。你可以在下面运行这个 demo。不要忘记提交成功时它会 POST 到一个临时的 URL。 + +

CodePen 查看 Raymond Camden (@cfjedimaster) 的 表单校验 1

+ + +## 使用自定义校验 + +对于第二个示例来说,第二个文本字段 (年龄) 变换成了电子邮件地址,它将会通过一些自定义的逻辑来校验。这部分代码来自 StackOverflow 的问题:[如何在 JavaScript 中校验电子邮件地址](https://stackoverflow.com/questions/46155/how-to-validate-email-address-in-javascript)。这是一个很好的问题,因为它会让 Facebook 上最激烈的政治、宗教争论看上去都只是“哪家的啤酒最好喝”这样的小分歧了。讲真的这很疯狂。我们来看 HTML,尽管它和第一个例子很接近。 + +``` html + + +

+ Please correct the following error(s): +

+

+ +

+ + +

+ +

+ + +

+ +

+ + +

+ +

+ +

+ +
+``` + +尽管这里的不同点很小,注意顶端的 `novalidate="true"`。但是这很重要,因为浏览器会尝试在 `type="email"` 的字段校验邮件地址。坦白说在这个案例中浏览器的校验规则是值得信任的,不过我们想要创建一个自定义校验的例子,所以把它禁用了。以下是更新后的 JavaScript。 + +``` js +const app = new Vue({ + el: '#app', + data: { + errors: [], + name: null, + email: null, + movie: null + }, + methods: { + checkForm: function (e) { + this.errors = []; + + if (!this.name) { + this.errors.push("Name required."); + } + if (!this.email) { + this.errors.push('Email required.'); + } else if (!this.validEmail(this.email)) { + this.errors.push('Valid email required.'); + } + + if (!this.errors.length) { + return true; + } + + e.preventDefault(); + }, + validEmail: function (email) { + var re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; + return re.test(email); + } + } +}) +``` + +如你所见,我们添加了一个新方法 `validEmail`,它将会在 `checkForm` 中被调用了。我们现在可以这样运行示例: + +

CodePen 查看 Raymond Camden (@cfjedimaster) 的 表单校验 2

+ + +## 另一个自定义校验的例子 + +在第三个示例中,我们已经构建了一些你可能在一些调研类应用中见过的东西。用户需要花掉“预算”来为歼星舰模型装配一套部件。总价必须等于 100。先看 HTML。 + +``` html +
+ +

+ Please correct the following error(s): +

+

+ +

+ Given a budget of 100 dollars, indicate how much + you would spend on the following features for the + next generation Star Destroyer. Your total must sum up to 100. +

+ +

+ Weapons
+ Shields
+ Coffee
+ Air Conditioning
+ Mouse Droids
+

+ +

+ Current Total: {{total}} +

+ +

+ +

+ +
+``` + +这组输入框覆盖了五个不同的部件。注意这里为 `v-model` 特性添加了 `.number`。它会告诉 Vue 将其值作为数字来使用。不过这里有一个小小的 bug,那就是当其值为空的时候,它会回到字符串格式,稍后你将会看到变通的办法。为了让用户使用起来更方便,我们添加展示了一个当前的总和,这样我们就能够实时的看到它们一共花掉了多少钱。现在我们来看看 JavaScript。 + +``` js +const app = new Vue({ + el: '#app', + data:{ + errors: [], + weapons: 0, + shields: 0, + coffee: 0, + ac: 0, + mousedroids: 0 + }, + computed: { + total: function () { + // 必须解析,因为 Vue 会将空值转换为字符串 + return Number(this.weapons) + + Number(this.shields) + + Number(this.coffee) + + Number(this.ac+this.mousedroids); + } + }, + methods:{ + checkForm: function (e) { + this.errors = []; + + if (this.total != 100) { + this.errors.push('Total must be 100!'); + } + + if (!this.errors.length) { + return true; + } + + e.preventDefault(); + } + } +}) +``` + +我们将总和设置为了一个计算属性,从那个我们解决掉的 bug 外面看上去,这已经足够了。我的 `checkForm` 方法现在只需要关注总和是不是 100 了。你可以在这里试用: + +

CodePen 查看 Raymond Camden (@cfjedimaster) 的 表单校验3

+ + +## 服务端校验 + +在我们最终的示例中,我们构建了一些用到 Ajax 的服务端校验的东西。这个表单将会问你为一个新产品起名字,并且将会确保这个名字是唯一的。我们快速写了一个 [OpenWhisk](http://openwhisk.apache.org/) 的 serverless action 来进行这个校验。虽然这不是非常重要,但其逻辑如下: + +``` js +function main(args) { + return new Promise((resolve, reject) => { + // 不好的产品名:vista, empire, mbp + const badNames = ['vista', 'empire', 'mbp']; + + if (badNames.includes(args.name)) { + reject({error: 'Existing product'}); + } + + resolve({status: 'ok'}); + }); +} +``` + +基本上除了“vista”、“empire”和“mbp”的名字都是可以接受的。好,让我们来看看表单。 + +``` html +
+ +

+ Please correct the following error(s): +

+

+ +

+ + +

+ +

+ +

+ +
+``` + +这里没有任何特殊的东西。接下来我们再看看 JavaScript。 + +``` js +const apiUrl = 'https://openwhisk.ng.bluemix.net/api/v1/web/rcamden%40us.ibm.com_My%20Space/safeToDelete/productName.json?name='; + +const app = new Vue({ + el: '#app', + data: { + errors: [], + name: '' + }, + methods:{ + checkForm: function (e) { + e.preventDefault(); + + this.errors = []; + + if (this.name === '') { + this.errors.push('Product name is required.'); + } else { + fetch(apiUrl + encodeURIComponent(this.name)) + .then(res => res.json()) + .then(res => { + if (res.error) { + this.errors.push(res.error); + } else { + // 在成功的时候重定向到一个新的 URL 或做一些别的事情 + alert('ok!'); + } + }); + } + } + } +}) +``` + +我们从一个运行在 OpenWhisk 的 API 的 URL 变量开始。现在注意 `checkForm`。在这个版本中,我们始终阻止了表单的提交 (当然,它也可以通过 Vue 在 HTML 中完成)。你可以看到一个基本的校验,即 `this.name` 是否为空,然后我们请求这个 API。如果名字是无效的,我们就添加一个错误。如果是有效的,我们就不做任何事 (只是一个 alert),但是你可以引导用户去一个新页面,在 URL 中带上产品的名字,或者其它行为。接下来你可以体验这个 demo: + +

CodePen 查看 Raymond Camden (@cfjedimaster) 的 表单校验4。

+ + +## 其它替代模式 + +这份秘笈专注在“手动”校验表单,当然一些非常棒的 Vue 的库会为你搞定这些事情。使用一些预打包的库可能会影响你的应用最终的体积,但是好处是非常多的。这里有经过充分测试且保持日常更新的代码。其中包括以下 Vue 的表单校验库: + +* [vuelidate](https://github.com/monterail/vuelidate) +* [VeeValidate](https://logaretm.github.io/vee-validate/) diff --git a/src/v2/examples/themes.md b/src/v2/examples/themes.md deleted file mode 100644 index 33611cb66..000000000 --- a/src/v2/examples/themes.md +++ /dev/null @@ -1,116 +0,0 @@ ---- -title: 主题 -type: examples -is_new: true -order: 13 ---- -> 通过合作伙伴 [Creative Tim](https://creative-tim.com?affiliate_id=116187) 创建的例子,你可以在一个真实的应用中看到它是如何构建起来的,它背后的技术栈以及你学到的大部分概念。 - -{% raw %} -
-
- - -
-

{{product.title}}

- {{product.price}}$ -
-
{{product.description}}
-
-
- - 查看更多主题 - -
-
- -{% endraw %} diff --git a/src/v2/guide/class-and-style.md b/src/v2/guide/class-and-style.md index de9a0b570..7239b3a98 100644 --- a/src/v2/guide/class-and-style.md +++ b/src/v2/guide/class-and-style.md @@ -7,7 +7,8 @@ order: 6 操作元素的 class 列表和内联样式是数据绑定的一个常见需求。因为它们都是属性,所以我们可以用 `v-bind` 处理它们:只需要通过表达式计算出字符串结果即可。不过,字符串拼接麻烦且易错。因此,在将 `v-bind` 用于 `class` 和 `style` 时,Vue.js 做了专门的增强。表达式结果的类型除了字符串之外,还可以是对象或数组。 ## 绑定 HTML Class -
观看本节视频讲解
+ +
观看本节视频讲解
### 对象语法 diff --git a/src/v2/guide/components-dynamic-async.md b/src/v2/guide/components-dynamic-async.md index 2e509b64b..f40c9c041 100644 --- a/src/v2/guide/components-dynamic-async.md +++ b/src/v2/guide/components-dynamic-async.md @@ -201,7 +201,7 @@ new Vue({ ## 异步组件 -
Watch a free video lesson on Vue School
+
Watch a free video lesson on Vue School
在大型应用中,我们可能需要将应用分割成小一些的代码块,并且只在需要的时候才从服务器加载一个模块。为了简化,Vue 允许你以一个工厂函数的方式定义你的组件,这个工厂函数会异步解析你的组件定义。Vue 只有在这个组件需要被渲染的时候才会触发该工厂函数,且会把结果缓存起来供未来重渲染。例如: diff --git a/src/v2/guide/components-registration.md b/src/v2/guide/components-registration.md index 6c274acfb..c4431cf5d 100644 --- a/src/v2/guide/components-registration.md +++ b/src/v2/guide/components-registration.md @@ -6,7 +6,7 @@ order: 101 > 该页面假设你已经阅读过了[组件基础](components.html)。如果你还对组件不太了解,推荐你先阅读它。 -
观看本节视频讲解
+
观看本节视频讲解
## 组件名 diff --git a/src/v2/guide/components.md b/src/v2/guide/components.md index fe8742e13..bf774bb68 100644 --- a/src/v2/guide/components.md +++ b/src/v2/guide/components.md @@ -4,11 +4,10 @@ type: guide order: 11 --- +
观看本节视频讲解
## 基本示例 -
观看本节视频讲解
- 这里有一个 Vue 组件的示例: ``` js diff --git a/src/v2/guide/conditional.md b/src/v2/guide/conditional.md index 1f9f24ba7..ea4e88637 100644 --- a/src/v2/guide/conditional.md +++ b/src/v2/guide/conditional.md @@ -6,7 +6,7 @@ order: 7 ## `v-if` -
观看本节视频讲解
+
观看本节视频讲解
`v-if` 指令用于条件性地渲染一块内容。这块内容只会在指令的表达式返回 truthy 值的时候被渲染。 diff --git a/src/v2/guide/custom-directive.md b/src/v2/guide/custom-directive.md index 37656a68c..9be0b48fb 100644 --- a/src/v2/guide/custom-directive.md +++ b/src/v2/guide/custom-directive.md @@ -6,7 +6,7 @@ order: 302 ## 简介 -
Watch a free video lesson on Vue School
+
Watch a free video lesson on Vue School
除了核心功能默认内置的指令 (`v-model` 和 `v-show`),Vue 也允许注册自定义指令。注意,在 Vue2.0 中,代码复用和抽象的主要形式是组件。然而,有的情况下,你仍然需要对普通 DOM 元素进行底层操作,这时候就会用到自定义指令。举个聚焦输入框的例子,如下: diff --git a/src/v2/guide/events.md b/src/v2/guide/events.md index 969539b91..759a74cfa 100644 --- a/src/v2/guide/events.md +++ b/src/v2/guide/events.md @@ -6,7 +6,7 @@ order: 9 ## 监听事件 -
观看本节视频讲解
+
观看本节视频讲解
可以用 `v-on` 指令监听 DOM 事件,并在触发时运行一些 JavaScript 代码。 diff --git a/src/v2/guide/forms.md b/src/v2/guide/forms.md index 97e51e0a0..6fc11b218 100644 --- a/src/v2/guide/forms.md +++ b/src/v2/guide/forms.md @@ -6,7 +6,7 @@ order: 10 ## 基础用法 -
观看本节视频讲解
+
观看本节视频讲解
你可以用 `v-model` 指令在表单 ``、`