Skip to content

Commit 062ea9f

Browse files
authored
Merge branch 'master' into SmartXXI-patch-2
2 parents c1212ae + b15b22a commit 062ea9f

37 files changed

+198
-37506
lines changed

src/v2/guide/components-custom-events.md

+36-36
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,34 @@ type: guide
44
order: 103
55
---
66

7-
> This page assumes you've already read the [Components Basics](components.html). Read that first if you are new to components.
7+
> Даний розділ передбачає, що ви вже знайомі [компонентами](components.html). Прочитайте його, якщо це не так.
88
9-
<div class="vueschool"><a href="https://vueschool.io/lessons/communication-between-components?friend=vuejs" target="_blank" rel="sponsored noopener" title="Learn how to work with custom events on Vue School">Learn how to work with custom events in a free Vue School lesson</a></div>
9+
<div class="vueschool"><a href="https://vueschool.io/lessons/communication-between-components?friend=vuejs" target="_blank" rel="sponsored noopener" title="Дізнайтеся, як працювати із спеціальними подіями в Vue School">Дізнайтеся, як працювати із спеціальними подіями на безкоштовному уроці в Vue School lesson</a></div>
1010

11-
## Event Names
11+
## Імена подій
1212

13-
Unlike components and props, event names don't provide any automatic case transformation. Instead, the name of an emitted event must exactly match the name used to listen to that event. For example, if emitting a camelCased event name:
13+
На відміну від компонентів та вхідних параметрів, імена подій не трансформуються автоматично. Навпаки, ім'я згенерованої події має бути точно таким самим, як і ім'я, що використовується для її відстежування. Ось приклад, якщо згенероване ім'я події в стилі camelCase:
1414

1515
```js
1616
this.$emit('myEvent')
1717
```
1818

19-
Listening to the kebab-cased version will have no effect:
19+
Відстежуванні події за її іменем в стилі kebab-cased не працюватиме:
2020

2121
```html
22-
<!-- Won't work -->
22+
<!-- Це не працюватиме -->
2323
<my-component v-on:my-event="doSomething"></my-component>
2424
```
2525

26-
Unlike components and props, event names will never be used as variable or property names in JavaScript, so there's no reason to use camelCase or PascalCase. Additionally, `v-on` event listeners inside DOM templates will be automatically transformed to lowercase (due to HTML's case-insensitivity), so `v-on:myEvent` would become `v-on:myevent` -- making `myEvent` impossible to listen to.
26+
На відміну від компонентів та вхідних параметрів, імена подій не будуть використовуватися як змінна або властивість в JavaScript, тому нема змісту використовувати camelCase чи PascalCase. Крім того, слухач подій `v-on` всередині DOM шаблонів будуть автоматично трансформовані до нижнього регістру (у зв'язку з ігноруванням регістру в стандарті HTML), тому `v-on:myEvent` стане `v-on:myevent`, роблячи `myEvent` неможливим для відстежування.
2727

28-
For these reasons, we recommend you **always use kebab-case for event names**.
28+
З цих причин, ми радимо вам **завжди задавати імена подій в стилі kebab-case**.
2929

30-
## Customizing Component `v-model`
30+
## Налаштування `v-model` компонента
3131

32-
> New in 2.2.0+
32+
> Нове в 2.2.0+
3333
34-
By default, `v-model` on a component uses `value` as the prop and `input` as the event, but some input types such as checkboxes and radio buttons may want to use the `value` attribute for a [different purpose](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/checkbox#Value). Using the `model` option can avoid a conflict in such cases:
34+
За замовчуванням, `v-model` в компонента використовує `value` як вхідний параметр та `input` як ім'я події, але деякі типи елементів введення, такі як прапорці та радіо кнопки можуть використовувати атрибут `value` [різних потреб (англ.)](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/checkbox#Value). Використання параметру `model` може запобігти конфліктів у випадках:
3535

3636
```js
3737
Vue.component('base-checkbox', {
@@ -52,25 +52,25 @@ Vue.component('base-checkbox', {
5252
})
5353
```
5454

55-
Now when using `v-model` on this component:
55+
Тепер при використанні у цьому компоненті `v-model`:
5656

5757
```html
5858
<base-checkbox v-model="lovingVue"></base-checkbox>
5959
```
6060

61-
the value of `lovingVue` will be passed to the `checked` prop. The `lovingVue` property will then be updated when `<base-checkbox>` emits a `change` event with a new value.
61+
значення властивості `lovingVue` буде передане до вхідного параметра `checked`. Властивість `lovingVue` буде оновлена згодом, коли `<base-checkbox>` згенерує подію `change` із новим значенням.
6262

63-
<p class="tip">Note that you still have to declare the <code>checked</code> prop in the component's <code>props</code> option.</p>
63+
<p class="tip">Зверніть увагу, що ви все одно повинні оголосити вхідний параметр <code>checked</code> в об'єкті <code>props</code> компонента.</p>
6464

65-
## Binding Native Events to Components
65+
## Зв'язування рідних подій в компоненті
6666

67-
There may be times when you want to listen directly to a native event on the root element of a component. In these cases, you can use the `.native` modifier for `v-on`:
67+
Інколи може виникати необхідність, коли ви хочете відстежувати рідну подію на кореневому елементі компонента. В такому разі, ви можете використовувати модифікатор `.native` при`v-on`:
6868

6969
```html
7070
<base-input v-on:focus.native="onFocus"></base-input>
7171
```
7272

73-
This can be useful sometimes, but it's not a good idea when you're trying to listen on a very specific element, like an `<input>`. For example, the `<base-input>` component above might refactor so that the root element is actually a `<label>` element:
73+
Це інколи може бути корисним, але не є найкращою ідеєю при спробі відстежування на якомусь конкретному елементі, наприклад `<input>`. Для прикладу, компонент `<base-input>`, що вище можна змінити таким чином, що кореневим елементом буде `<label>`:
7474

7575
```html
7676
<label>
@@ -83,9 +83,9 @@ This can be useful sometimes, but it's not a good idea when you're trying to lis
8383
</label>
8484
```
8585

86-
In that case, the `.native` listener in the parent would silently break. There would be no errors, but the `onFocus` handler wouldn't be called when we expected it to.
86+
В даному випадку, слухач `.native` в батьківському компоненті просто тихо зламається. Не буде ніяких помилок, але обробник `onFocus` не буде викликаний, як це очікувалось.
8787

88-
To solve this problem, Vue provides a `$listeners` property containing an object of listeners being used on the component. For example:
88+
Для розв'язання цієї проблеми, Vue пропонує властивість `$listeners`, яка містить об'єкт слухачів, які використовуються в компоненті. Наприклад:
8989

9090
```js
9191
{
@@ -94,7 +94,7 @@ To solve this problem, Vue provides a `$listeners` property containing an object
9494
}
9595
```
9696

97-
Using the `$listeners` property, you can forward all event listeners on the component to a specific child element with `v-on="$listeners"`. For elements like `<input>`, that you also want to work with `v-model`, it's often useful to create a new computed property for listeners, like `inputListeners` below:
97+
Використовуючи властивість `$listeners`, ви можете переадресувати всі слухачі компонента специфічному дочірньому елементу за допомогою `v-on="$listeners"`. Для елементів, подібних до `<input>`, які також можуть працювати з `v-model`, часто корисно створювати нову обчислювану властивість для слухачів, як-от `inputListeners`:
9898

9999
```js
100100
Vue.component('base-input', {
@@ -103,14 +103,14 @@ Vue.component('base-input', {
103103
computed: {
104104
inputListeners: function () {
105105
var vm = this
106-
// `Object.assign` merges objects together to form a new object
106+
// `Object.assign` формує новий об'єкт, об'єднуючи об'єкти разом
107107
return Object.assign({},
108-
// We add all the listeners from the parent
108+
// Додаємо всіх слухачів з батьківського компонента
109109
this.$listeners,
110-
// Then we can add custom listeners or override the
111-
// behavior of some listeners.
110+
// Тепер ми можемо додати власних слухачів або перезаписати
111+
// поведінку деяких наявних слухачів.
112112
{
113-
// This ensures that the component works with v-model
113+
// Таким чином, ми переконаємося, що компонент працює v-model
114114
input: function (event) {
115115
vm.$emit('input', event.target.value)
116116
}
@@ -131,21 +131,21 @@ Vue.component('base-input', {
131131
})
132132
```
133133

134-
Now the `<base-input>` component is a **fully transparent wrapper**, meaning it can be used exactly like a normal `<input>` element: all the same attributes and listeners will work, without the `.native` modifier.
134+
Тепер компонент `<base-input>` є **повністю прозорою обгорткою**, маючи на увазі, що він може використовуватися як і звичайний елемент `<input>`: всі ті ж атрибути та слухачі працюватимуть навіть без модифікатора `.native`.
135135

136-
## `.sync` Modifier
136+
## Модифікатор `.sync`
137137

138-
> New in 2.3.0+
138+
> Нове в 2.3.0+
139139
140-
In some cases, we may need "two-way binding" for a prop. Unfortunately, true two-way binding can create maintenance issues, because child components can mutate the parent without the source of that mutation being obvious in both the parent and the child.
140+
В деяких випадках може виникнути потреба використовувати "двонаправлене зв'язування" для вхідного параметра. Правда у тім, що, на жаль, таке зв'язування може створити певні проблеми з обслуговуванням, оскільки дочірні компоненти можуть мутувати батьківські без очевидного розуміння джерела такої мутації для батьківського та дочірнього компонента.
141141

142-
That's why instead, we recommend emitting events in the pattern of `update:myPropName`. For example, in a hypothetical component with a `title` prop, we could communicate the intent of assigning a new value with:
142+
Ось чому ви радимо генерувати події у вигляді `update:myPropName`. Для прикладу, в гіпотетичного компонента із вхідним параметром `title`, ми можемо повідомити про намір присвоєння нового значення за допомогою:
143143

144144
```js
145145
this.$emit('update:title', newTitle)
146146
```
147147

148-
Then the parent can listen to that event and update a local data property, if it wants to. For example:
148+
Потім, батьківський компонент може прослуховувати цю подію та оновити локальну властивість даних, якщо йому це потрібно. Наприклад:
149149

150150
```html
151151
<text-document
@@ -154,20 +154,20 @@ Then the parent can listen to that event and update a local data property, if it
154154
></text-document>
155155
```
156156

157-
For convenience, we offer a shorthand for this pattern with the `.sync` modifier:
157+
Для зручності, ми пропонуємо скорочення для цієї техніки — модифікатор `.sync`:
158158

159159
```html
160160
<text-document v-bind:title.sync="doc.title"></text-document>
161161
```
162162

163-
<p class="tip">Note that <code>v-bind</code> with the <code>.sync</code> modifier does <strong>not</strong> work with expressions (e.g. <code>v-bind:title.sync="doc.title + '!'"</code> is invalid). Instead, you must only provide the name of the property you want to bind, similar to <code>v-model</code>.</p>
163+
<p class="tip">Зверніть увагу, що <code>v-bind</code> із модифікатором <code>.sync</code> <strong>не</strong> працює з виразами (тобто, <code>v-bind:title.sync="doc.title + '!'"</code> є невірним). Тому, ви повинні вказувати лише ім'я властивості, яку ви хочете прив'язати, подібно до <code>v-model</code>.</p>
164164

165-
The `.sync` modifier can also be used with `v-bind` when using an object to set multiple props at once:
165+
Модифікатор `.sync` може також використовуватись разом з `v-bind` при використанні об'єкта для задавання кількох властивостей за раз:
166166

167167
```html
168168
<text-document v-bind.sync="doc"></text-document>
169169
```
170170

171-
This passes each property in the `doc` object (e.g. `title`) as an individual prop, then adds `v-on` update listeners for each one.
171+
Це передає кожну властивість в об'єкті `doc` (тобто, `title`) як окремий вхдний параметр, потім додаючи слухач `v-on` для кожної з них.
172172

173-
<p class="tip">Using <code>v-bind.sync</code> with a literal object, such as in <code>v-bind.sync="{ title: doc.title }"</code>, will not work, because there are too many edge cases to consider in parsing a complex expression like this.</p>
173+
<p class="tip">Застосування <code>v-bind.sync</code> з літеральним об'єктом, як, наприклад, через <code>v-bind.sync="{ title: doc.title }"</code>, не працюватиме, оскільки існує забагато крайніх випадків, необхідних для прийняття до уваги при розборі складного виразу, такого, як цей.</p>

0 commit comments

Comments
 (0)