-
Notifications
You must be signed in to change notification settings - Fork 103
v2/guide/instance.md - proposition de traduction #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
e1a5550
59a49b3
412bac9
1aefd6a
cd59fd1
0270438
b0d1a52
4e1fa5b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,42 @@ | ||
--- | ||
title: The Vue Instance | ||
title: L'instance de Vue | ||
type: guide | ||
order: 3 | ||
--- | ||
|
||
## Constructor | ||
## Constructeur | ||
|
||
<p class="tip">**Cette page est en cours de traduction française. Revenez une autre fois pour lire une traduction achevée ou [participez à la traduction française ici](https://github.com/vuejs-fr/vuejs.org).**</p>Every Vue vm is bootstrapped by creating a **root Vue instance** with the `Vue` constructor function: | ||
Chaque Vue vm est initialisée en créant une **instance racine de Vue** avec le constructeur de la fonction `Vue` | ||
|
||
``` js | ||
var vm = new Vue({ | ||
// options | ||
}) | ||
``` | ||
|
||
Although not strictly associated with the [MVVM pattern](https://en.wikipedia.org/wiki/Model_View_ViewModel), Vue's design was partly inspired by it. As a convention, we often use the variable `vm` (short for ViewModel) to refer to our Vue instances. | ||
Bien que n'étant pas strictement associée au patron d'architecture [MVVM pattern](https://en.wikipedia.org/wiki/Model_View_ViewModel), La conception de Vue s'en est en partie inspirée. Par convetion, nous utilisons souvent la variable `vm` (abréviation pour ViewModel) pour faire référence à nos instances de Vue. | ||
|
||
When you instantiate a Vue instance, you need to pass in an **options object** which can contain options for data, template, element to mount on, methods, lifecycle callbacks and more. The full list of options can be found in the [API reference](../api). | ||
Quand vous créez une instance de Vue, vous devez passer un **objet d'options** qui contient les options pour les data, le template, l'element de montage, les methodes, les fonctions de retour du cycle de vie etc... La liste des options peut être trouvée [dans la documentation de l'API](../api). | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. méthodes |
||
|
||
The `Vue` constructor can be extended to create reusable **component constructors** with pre-defined options: | ||
Le constructeur de `Vue` peut être étendu pour créer des **constructeurs de composants** réutilisables avec des options prédéfinies. | ||
|
||
``` js | ||
var MyComponent = Vue.extend({ | ||
// extension options | ||
// options d'extension | ||
}) | ||
|
||
// all instances of `MyComponent` are created with | ||
// the pre-defined extension options | ||
// toutes les isntances de `MyComponent` sont créees avec | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. instances (typo) créées |
||
// les options d'extension prédéfinies | ||
var myComponentInstance = new MyComponent() | ||
``` | ||
|
||
Although it is possible to create extended instances imperatively, most of the time it is recommended to compose them declaratively in templates as custom elements. We will talk about [the component system](components.html) in detail later. For now, you just need to know that all Vue components are essentially extended Vue instances. | ||
Bien qu'il soit possible de créer des instances étendues de manière impérative, la plupart du temps il est recommandé de les composer de manière déclarative dans les templates en tant qu'éléments custom. Nous parlerons du [système de composants](components.html) en détail plus loin. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. éléments custom => éléments personnalisés ? à définir dans #4 |
||
Pour le moment, vous avez juste besoin de savoir que tous les composants de Vue sont fondamentalement des instances de Vue étendues. | ||
|
||
## Properties and Methods | ||
## Propriétés et méthodes | ||
|
||
Chaque instance de vue **reflète ( ou référence )** toutes les propriétés contenues dans son objet "data" | ||
|
||
Each Vue instance **proxies** all the properties found in its `data` object: | ||
|
||
``` js | ||
var data = { a: 1 } | ||
|
@@ -44,18 +46,18 @@ var vm = new Vue({ | |
|
||
vm.a === data.a // -> true | ||
|
||
// setting the property also affects original data | ||
// affecter la propriété affecte également la donnée originale | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. assigner la propriété |
||
vm.a = 2 | ||
data.a // -> 2 | ||
|
||
// ... and vice-versa | ||
// ... et vice-versa | ||
data.a = 3 | ||
vm.a // -> 3 | ||
``` | ||
|
||
It should be noted that only these proxied properties are **reactive**. If you attach a new property to the instance after it has been created, it will not trigger any view updates. We will discuss the reactivity system in detail later. | ||
Soulignons que seuls ces propriétés reflétées sont réactives. Si vous attachez une nouvelle propriété à l'instance après sa création, elle ne déclenchera aucune mise à jour de la vue. Nous parlerons plus loin du système de réactivité en détail. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. seules ces propriétés proxied => j'ai déjà vu "proxifiées" dans certaines traductions mais aucune trace officielle dans un dico, seul le nom commun proxy est francisé. à discuter dans #4 comment on traduit cela, le mot est utilisé un peu partout sur le site. |
||
|
||
In addition to data properties, Vue instances expose a number of useful instance properties and methods. These properties and methods are prefixed with `$` to differentiate them from proxied data properties. For example: | ||
En plus des propriétés de data, les instances de Vue exposent de nombreuses méthodes et propriétés utiles. Ces propriétés et méthodes sont préfixées par `$` pour les différencier des propriétés reflétées de data. Par exemple : | ||
|
||
``` js | ||
var data = { a: 1 } | ||
|
@@ -67,37 +69,40 @@ var vm = new Vue({ | |
vm.$data === data // -> true | ||
vm.$el === document.getElementById('example') // -> true | ||
|
||
// $watch is an instance method | ||
// $watch est une méthode de l'instance | ||
vm.$watch('a', function (newVal, oldVal) { | ||
// this callback will be called when `vm.a` changes | ||
// cette fonction de retour sera appellée quand `vm.a` changera | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. appelée |
||
}) | ||
``` | ||
|
||
<p class="tip">Don't use [arrow functions](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Functions/Arrow_functions) on an instance property or callback (e.g. `vm.$watch('a', newVal => this.myMethod())`). As arrow functions are bound to the parent context, `this` will not be the Vue instance as you'd expect and `this.myMethod` will be undefined.</p> | ||
<p class="tip"> | ||
N'utilisez pas les [fonctions fléchées](https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Fonctions/Fonctions_fl%C3%A9ch%C3%A9es) sur une propriété ou fonction de retour d'une instance (par exemple `vm.$watch('a', newVal => this.myMethod())`). Comme les fonctions fléchées sont liées au contexte parent, `this` ne sera pas l'instance de Vue comme vous pourriez vous y attendre et `this.myMethod` sera indéfini. | ||
</p> | ||
|
||
Consult the [API reference](../api) for the full list of instance properties and methods. | ||
Consultez [l'API](../api) pour une liste complète des propriétés et méthodes d'une instance. | ||
|
||
## Instance Lifecycle Hooks | ||
## Les hooks de cycles de vie d'une instance | ||
|
||
Each Vue instance goes through a series of initialization steps when it is created - for example, it needs to set up data observation, compile the template, mount the instance to the DOM, and update the DOM when data changes. Along the way, it will also invoke some **lifecycle hooks**, which give us the opportunity to execute custom logic. For example, the `created` hook is called after the instance is created: | ||
Chaque instance de vue traverse une série d'étapes d'initialisations au moment de sa création - par exemple, elle doit mettre en place l'observation des data, compiler le template, monter l'instance sur le DOM et mettre à jour le DOM quand les data changent. En cours de route, elle va aussi invoquer des **hooks de cycles de vie**, qui nous donnent l'opportunité d'exécuter de la logique custom. Par exemple, le hook `created` est appelé après que l'instance sera créee. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. d'initialisation exécuter une logique personnalisée le hook (c'est aussi le genre de paragraphe où je trouve que "données" est plus parlant que "data", mais ce n'est que mon point de vue) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ca sonne bizarre en effet, je vais mettre données dans ce genre de phrase |
||
|
||
``` js | ||
var vm = new Vue({ | ||
data: { | ||
a: 1 | ||
}, | ||
created: function () { | ||
// `this` points to the vm instance | ||
// `this` référence l'instance de vm | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. référence à There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pas compris, pour moi c'est le verbe référencer, donc this "référence" l'instance. Non ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this est la référence, pas ce qui référence. Même différence entre "this assigne" est "this est assigné à" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. okay pushé |
||
console.log('a is: ' + this.a) | ||
} | ||
}) | ||
// -> "a is: 1" | ||
``` | ||
|
||
There are also other hooks which will be called at different stages of the instance's lifecycle, for example `mounted`, `updated`, and `destroyed`. All lifecycle hooks are called with their `this` context pointing to the Vue instance invoking it. You may have been wondering where the concept of "controllers" lives in the Vue world and the answer is: there are no controllers. Your custom logic for a component would be split among these lifecycle hooks. | ||
Il y aussi d'autres hook qui seront appelés à différentes étapes d'un cycle de vie d'une instance, par exemple `mounted`, `updated`et `destroyed`. Tous ces hooks de cycles de vie sont appelés avec leur `this` pointant sur l'instance de la vue qui les invoquent. Vous vous êtes peut-être demandé où se trouvait le concept de 'controleur' dans le monde de Vue et la réponse est : il n'y pas de controleurs. Votre logique custom pour un composant sera partagée entre ces différents cycles de vie. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hooks du cycle de vie de l'instance hooks de cycle de vie qui les invoque. contrôleur contrôleurs logique personnalisée sera répartie entre ces hooks de cycle de vie. |
||
|
||
## Diagramme de cycles de vie | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cycle |
||
|
||
## Lifecycle Diagram | ||
Ci-dessous se trouve le diagramme d'un cycle de vie d'une instance. Vous n'avez pas besoin de tout comprendre de A à Z à ce stade, mais ce diagramme pourra vous être utile dans le futur. | ||
|
||
Below is a diagram for the instance lifecycle. You don't need to fully understand everything going on right now, but this diagram will be helpful in the future. | ||
|
||
 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
la conception (l minuscule)
convention (typo)