Skip to content

Commit 1a58494

Browse files
authored
Merge pull request #36 from vuefe/master
Master
2 parents 5ec09e7 + 46e08f8 commit 1a58494

File tree

6 files changed

+51
-6
lines changed

6 files changed

+51
-6
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
all: update deploy
22

33
deploy:
4-
rm -f db.json
4+
rm -rf public db.json
55
hexo generate
66
hexo deploy
77

src/api/index.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -706,8 +706,7 @@ type: api
706706
A hash of filters to be made available to the Vue instance.
707707

708708
- **See also:**
709-
- [Custom Filters](/guide/custom-filter.html)
710-
- [Assets Naming Convention](/guide/components.html#Assets-Naming-Convention)
709+
- [`Vue.filter`](#Vue-filter)
711710

712711
### components
713712

src/examples/firebase.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ type: examples
44
order: 2
55
---
66

7-
> This example uses [Firebase](https://www.firebase.com/) as the data persistence backend and syncs between clients in real time (you can try opening it in multiple browser tabs). In addition, it performs instant validation using computed properties and triggers CSS transitions when adding/removing items.
7+
> This example uses [Firebase](https://firebase.google.com/) as the data persistence backend and syncs between clients in real time (you can try opening it in multiple browser tabs). In addition, it performs instant validation using computed properties and triggers CSS transitions when adding/removing items.
88
99
<iframe width="100%" height="500" src="https://jsfiddle.net/yyx990803/hkrxmp0h/embedded/result,html,js,css" allowfullscreen="allowfullscreen" frameborder="0"></iframe>

src/guide/index.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,11 @@ Vue.component('todo-item', {
309309
var app7 = new Vue({
310310
el: '#app-7',
311311
data: {
312-
todos: [/* ... */]
312+
todos: [
313+
{ text: 'Learn JavaScript' },
314+
{ text: 'Learn Vue' },
315+
{ text: 'Build something awesome' }
316+
]
313317
}
314318
})
315319
```

src/guide/installation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ resolve: {
6969

7070
Some environments, such as Google Chrome Apps, enforce Content Security Policy (CSP), which prohibits the use of `new Function()` for evaluating expressions. The standalone build depends on this feature to compile templates, so is unusable in these environments.
7171

72-
On the other hand, the runtime-only build is fully CSP-compliant. When using the runtime-only build with [Webpack + vue-loader](https://github.com/vuejs-templates/webpack-simple-2.0) or [Browserify + vueify](https://github.com/vuejs-templates/browserify-simple-2.0), your templates will be precompiled into `render` functions which work perfectly in CSP environments.
72+
On the other hand, the runtime-only build is fully CSP-compliant. When using the runtime-only build with [Webpack + vue-loader](https://github.com/vuejs-templates/webpack-simple) or [Browserify + vueify](https://github.com/vuejs-templates/browserify-simple), your templates will be precompiled into `render` functions which work perfectly in CSP environments.
7373

7474
## 命令行工具
7575

src/guide/migration.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,6 +1014,48 @@ In many cases though, you'll still run into strange behavior (e.g. `0.035.toFixe
10141014
</div>
10151015
{% endraw %}
10161016

1017+
### Two-Way Filters <sup>deprecated</sup>
1018+
1019+
Some users have enjoyed using two-way filters with `v-model` to create interesting inputs with very little code. While seemingly simple however, two-way filters can also hide a great deal of complexity - and even encourage poor UX by delaying state updates. Instead, components are recommended as a more explicit and feature-rich way of creating custom inputs.
1020+
1021+
We'll now walk through an example of a filter provided by the community and offer tips for how to migrate away from two-way filters. Here's a simple currency filter:
1022+
1023+
<iframe width="100%" height="300" src="https://jsfiddle.net/chrisvfritz/6744xnjk/embedded/result,html,js" allowfullscreen="allowfullscreen" frameborder="0"></iframe>
1024+
1025+
It mostly works well, but the delayed state updates can cause strange behavior. For example, try entering `99.999` into one of those inputs. When the input loses focus, its value will update to `$100.00`. When looking at the calculated total however, you'll see that `99.999` is what's stored in our data. The version of reality that the user sees is out of sync!
1026+
1027+
To start transitioning towards a more robust solution using Vue 2.0, let's first refactor this filter into a component that uses it:
1028+
1029+
<iframe width="100%" height="300" src="https://jsfiddle.net/chrisvfritz/g7osemrx/embedded/result,html,js" allowfullscreen="allowfullscreen" frameborder="0"></iframe>
1030+
1031+
This allows us add behavior that wasn't possible with a filter alone, such as selecting the content of an input on focus. Now the next step will be to extract the business logic from the filter:
1032+
1033+
<iframe width="100%" height="300" src="https://jsfiddle.net/chrisvfritz/j4xtb20e/embedded/result,html,js" allowfullscreen="allowfullscreen" frameborder="0"></iframe>
1034+
1035+
This increased modularity not only makes it easier to migrate to Vue 2, but also allows currency parsing and formatting to be:
1036+
1037+
- unit tested in isolation from your Vue code
1038+
- used by other parts of your application, such as to validate the payload to an API endpoint
1039+
1040+
Having this validator extracted out, we can also more comfortably build it up into a more robust solution. We've now eliminated the state quirks and have even made it impossible for users to enter anything wrong, similar to what the browser's native number input tries to do.
1041+
1042+
We're still limited however, by filters and by Vue 1.0 in general, so let's complete the upgrade to Vue 2.0:
1043+
1044+
<iframe width="100%" height="300" src="https://jsfiddle.net/chrisvfritz/r4e49aLs/embedded/result,html,js" allowfullscreen="allowfullscreen" frameborder="0"></iframe>
1045+
1046+
You may notice that:
1047+
1048+
- Every aspect of our input is more explicit, using lifecycle hooks and DOM events in place of the hidden behavior of two-way filters.
1049+
- We can now use `v-model` directly on our custom inputs, which is not only more consistent with normal inputs, but also means our component is Vuex-friendly.
1050+
- Since we're no longer using filter options that require a value to be returned, our currency work could actually be done asynchronously. That means if we had a lot of apps that had to work with currencies, we could easily refactor this logic into a shared microservice.
1051+
1052+
{% raw %}
1053+
<div class="upgrade-path">
1054+
<h4>Upgrade Path</h4>
1055+
<p>Run the <a href="https://github.com/vuejs/vue-migration-helper">migration helper</a> on your codebase to find examples of filters used in directives like <code>v-model</code>. If you miss any, you should also see <strong>console errors</strong>.</p>
1056+
</div>
1057+
{% endraw %}
1058+
10171059
## Slots
10181060

10191061
### Duplicate Slots <sup>deprecated</sup>

0 commit comments

Comments
 (0)