Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Relecture de forms.md #16

Merged
merged 3 commits into from
Jun 23, 2017
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/en/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
- [Structure d'une application](structure.md)
- [Plugins](plugins.md)
- [Strict Mode](strict.md)
- [Formulaires](forms.md)
- [Gestion des formulaires](forms.md)
- [Tests](testing.md)
- [Hot Reloading](hot-reload.md)
- [Documentation API](api.md)
15 changes: 7 additions & 8 deletions docs/en/forms.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# Form Handling
# Gestion des formulaires

When using Vuex in strict mode, it could be a bit tricky to use `v-model` on a piece of state that belongs to Vuex:
Lorsque l'on utilise Vuex en mode strict, il peut être compliqué d'utiliser `v-model` sur une partie de l'état qui appartient à Vuex :

``` html
<input v-model="obj.message">
```

Assuming `obj` is a computed property that returns an Object from the store, the `v-model` here will attempt to directly mutate `obj.message` when the user types in the input. In strict mode, this will result in an error because the mutation is not performed inside an explicit Vuex mutation handler.
Supposons que `obj` est une propriété calculée qui retourne un objet depuis le store, le `v-model` tentera de muter directement `obj.message` lorsque l'utilisateur saisit du texte dans le champ. En mode strict, cela produira une erreur car la mutation n'est pas effectuée dans un gestionnaire de mutation Vuex explicite.

The "Vuex way" to deal with it is binding the `<input>`'s value and call an action on the `input` or `change` event:
La Vuex peut gérer ça en liant la valeur de l'`input` et en appelant une action sur l'évènement `input` ou `change` :
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

La « façon Vuex » pour gérer cela est de lier


``` html
<input :value="message" @input="updateMessage">
Expand All @@ -27,7 +27,7 @@ methods: {
}
```

And here's the mutation handler:
Et voici le gestionnaire de mutation :

``` js
// ...
Expand All @@ -38,9 +38,9 @@ mutations: {
}
```

### Two-way Computed Property
### Propriété calculée bidirectionnelle

Admittedly, the above is quite a bit more verbose than `v-model` + local state, and we lose some of the useful features from `v-model` as well. An alternative approach is using a two-way computed property with a setter:
Admettons tout de même que l'exemple ci-dessus est plus verbeux que le `v-model` couplé à l'état local tout en perdant quelques fonctionnalités pratiques de `v-model` au passage. Une approche alternative consiste à utiliser une propriété calculée bidirectionnelle avec un mutateur :

``` html
<input v-model="message">
Expand All @@ -58,4 +58,3 @@ computed: {
}
}
```