Skip to content

Update events.md #11

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

Merged
merged 3 commits into from
Sep 21, 2020
Merged

Update events.md #11

merged 3 commits into from
Sep 21, 2020

Conversation

SmartXXI
Copy link

Note

We're currently in the process of migrating Vue's documentation to v3. To ensure smooth progress, only PR's that fix critical bugs and/or misinformation will be accepted. If yours is not one of them, consider creating an issue instead and we will label it as post-3.0 for later tackling.

@@ -4,18 +4,19 @@ type: guide
order: 9
---

<div class="vueschool"><a href="https://vueschool.io/lessons/vuejs-user-events?friend=vuejs" target="_blank" rel="sponsored noopener" title="Learn how to handle events on Vue School">Learn how to handle events in a free Vue School lesson</a></div>
<div class="vueschool"><a href="https://vueschool.io/lessons/vuejs-user-events?friend=vuejs" target="_blank" rel="sponsored noopener" title="Дізнайся, як обробляти події на безкоштовному уроці Vue School">Дізнайся, як обробляти події на безкоштовному уроці Vue School</a></div>
Copy link
Member

Choose a reason for hiding this comment

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

Ми скрізь вживаємо "Дізнайтеся"


## Listening to Events
## Прослуховування подій

We can use the `v-on` directive to listen to DOM events and run some JavaScript when they're triggered.
Copy link
Member

Choose a reason for hiding this comment

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

Прохання видалити оригінал тут, та нижче


The logic for many event handlers will be more complex though, so keeping your JavaScript in the value of the `v-on` attribute isn't feasible. That's why `v-on` can also accept the name of a method you'd like to call.
Однак логіка для багатьох обробників подій буде більш складною, тому записати ваш JavaScript у значення атрибута `v-on` неможливе. Ось чому v-on також може прийняти назву методу, який ви хочете викликати.
Copy link
Member

Choose a reason for hiding this comment

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

Відсутня кома після "однак"

Copy link
Member

@matrunchyk matrunchyk Sep 17, 2020

Choose a reason for hiding this comment

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

Насправді, це можливо, але так робити не варто. Я б переклав як

.... тому зберігати JavaScript-код в якості значення атрибута v-on не підходить. Ось чому ... може ПРИЙМАТИ ....


For example:
На приклад:
Copy link
Member

Choose a reason for hiding this comment

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

"Наприклад:" - разом. Або ж виправити на "Спробуємо на прикладі:"


``` html
<div id="example-2">
<!-- `greet` is the name of a method defined below -->
<button v-on:click="greet">Greet</button>
<!-- `greet` є ім'ям методу визначеного нижче -->
Copy link
Member

Choose a reason for hiding this comment

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

після "методу" відсутня кома

<!-- `greet` is the name of a method defined below -->
<button v-on:click="greet">Greet</button>
<!-- `greet` є ім'ям методу визначеного нижче -->
<button v-on:click="greet">Чудово</button>
Copy link
Member

Choose a reason for hiding this comment

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

Greet - Привітати
Great - Чудово

},
// define methods under the `methods` object
// визначити метод в об'єкті "методи"
Copy link
Member

Choose a reason for hiding this comment

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

визначити метод в об'єкті методів
або
визначити метод в об'єкті "methods"


{% raw %}
<div id="example-2" class="demo">
<button v-on:click="greet">Greet</button>
<button v-on:click="greet">Чудово</button>
Copy link
Member

Choose a reason for hiding this comment

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

Привітати

<button v-on:click="say('hi')">Say hi</button>
<button v-on:click="say('what')">Say what</button>
<button v-on:click="say('Привіт')">Скажи привіт</button>
<button v-on:click="say('Що')">Скажи що</button>
Copy link
Member

Choose a reason for hiding this comment

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

"Say hi"
"Say what"

"Сказати привіт"
"Сказати що?"

</div>
```

``` js
var example2 = new Vue({
el: '#example-2',
data: {
name: 'Vue.js'
name: 'Vue.js',
Copy link
Member

Choose a reason for hiding this comment

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

Ми не можемо міняти форматування коду, можемо робити лише переклад

// `this` inside methods points to the Vue instance
alert('Hello ' + this.name + '!')
// `event` is the native DOM event
greet(event) {
Copy link
Member

Choose a reason for hiding this comment

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

Ми не можемо міняти форматування коду і переводити його на es6. Він навмисно був написаний в es5 режимі. Прохання повернути форматований та переведений на es6 код назад на оригінальний

}
}
```

## Event Modifiers
## Модифікатори подій

It is a very common need to call `event.preventDefault()` or `event.stopPropagation()` inside event handlers. Although we can do this easily inside methods, it would be better if the methods can be purely about data logic rather than having to deal with DOM event details.
Copy link
Member

Choose a reason for hiding this comment

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

залишки оригіналу

To address this problem, Vue provides **event modifiers** for `v-on`. Recall that modifiers are directive postfixes denoted by a dot.
Часто є необхідність викликати `event.preventDefault()` або `event.stopPropagation()` всередині обробників подій. Незважаючи на те, що ми можемо зробити це легко всередині методів, було б краще, якщо б методи використовували виключно логіку даних, а не мали справу з деталями подій DOM.

Для вирішення цієї проблеми Vue надає **модифікатори подій** для `v-on`. Нагадаємо, що модифікатори - це директивні постфікси, позначені крапкою.
Copy link
Member

@matrunchyk matrunchyk Sep 17, 2020

Choose a reason for hiding this comment

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

директивні постфікси, розділені крапкою

<a v-on:click.once="doThis"></a>
```

Unlike the other modifiers, which are exclusive to native DOM events, the `.once` modifier can also be used on [component events](components-custom-events.html). If you haven't read about components yet, don't worry about this for now.
На відміну від інших модифікаторів, які є лише для власних подій DOM, модифікатор `.once` також може використовуватися на [компонентах подій] (components-custom-events.html). Якщо ви ще не читали про компоненти, наразі не хвилюйтеся про це.
Copy link
Member

Choose a reason for hiding this comment

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

лишній пробіл перед відкриваючою круглою дужкою

Copy link
Member

Choose a reason for hiding this comment

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

пропоную перекласти "компонентах подій" на "спеціальні події", оскільки ця фраза містить посилання на одноіменний розділ https://vuejs.org.ua/v2/guide/components-custom-events.html

<input v-on:keyup.enter="submit">
```

You can directly use any valid key names exposed via [`KeyboardEvent.key`](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values) as modifiers by converting them to kebab-case.
Ви можете безпосередньо використовувати будь-які дійсні імена ключів, визначені у [`ПодіїКлавіатури.клавіші`](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values) як модифікатори перевівши їх у kebab-case.
Copy link
Member

Choose a reason for hiding this comment

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

KeyboardEvent.key не вимагає перекладу, оскільки це існуюче ім'я об'єкту


- `.enter`
- `.tab`
- `.delete` (captures both "Delete" and "Backspace" keys)
- `.delete` (перехоплює як клавіші "Delete" так і "Backspace")
Copy link
Member

Choose a reason for hiding this comment

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

перед "так" відсутня кома


### `.exact` Modifier
### `.exact` Модифікатор
Copy link
Member

@matrunchyk matrunchyk Sep 17, 2020

Choose a reason for hiding this comment

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

.exact модифікатор

або

Модифікатор .exact

<button v-on:click.exact="onClick">A</button>
```

### Mouse Button Modifiers
### Модифікатори клафіш миші
Copy link
Member

Choose a reason for hiding this comment

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

клавіш


You might be concerned that this whole event listening approach violates the good old rules about "separation of concerns". Rest assured - since all Vue handler functions and expressions are strictly bound to the ViewModel that's handling the current view, it won't cause any maintenance difficulty. In fact, there are several benefits in using `v-on`:
Ви можете бути стурбовані тим, що весь цей підхід до прослуховування подій порушує старі добрі правила щодо "відокремлення проблем". Будьте впевнені - оскільки всі функції та вирази обробника Vue суворо пов’язані з ViewModel, який обробляє поточний вигляд, це не спричинить труднощів з технічним обслуговуванням. Насправді використання "v-on" має кілька переваг:
Copy link
Member

Choose a reason for hiding this comment

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

Після "Насправді" відсутня кома


1. It's easier to locate the handler function implementations within your JS code by skimming the HTML template.
1. Простіше знайти реалізації функції обробника в коді JS, обробивши шаблон HTML.
Copy link
Member

Choose a reason for hiding this comment

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

Не дуже зрозумілий переклад. Як щодо

Простіше знайти функцію-обробник події у вашому JS коді простим переглядом HTML шаблону.

Copy link
Member

@matrunchyk matrunchyk left a comment

Choose a reason for hiding this comment

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

Please see the comments above

@matrunchyk matrunchyk merged commit 756428c into master Sep 21, 2020
@matrunchyk matrunchyk deleted the SmartXXI-patch-2 branch September 21, 2020 10:19
@matrunchyk
Copy link
Member

Fixes #9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants