You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The`$emit()`method is also available on the component instance as`this.$emit()`:
40
+
التابع`$emit()`متوفر أيضًا على نسخة المكون باستخدام`this.$emit()`:
40
41
41
42
```js
42
43
exportdefault {
@@ -50,48 +51,50 @@ export default {
50
51
51
52
</div>
52
53
53
-
The parent can then listen to it using`v-on`:
54
+
المكون الأب يمكنه الاستماع لها باستخدام`v-on`:
54
55
55
56
```vue-html
56
57
<MyComponent @some-event="callback" />
57
58
```
58
59
59
-
The`.once`modifier is also supported on component event listeners:
60
+
المعدل`.once`مدعوم أيضًا على مستمعي أحداث المكون:
60
61
61
62
```vue-html
62
63
<MyComponent @some-event.once="callback" />
63
64
```
64
65
65
-
Like components and props, event names provide an automatic case transformation. Notice we emitted a camelCase event, but can listen for it using a kebab-cased listener in the parent. As with [props casing](/guide/components/props.html#prop-name-casing), we recommend using kebab-cased event listeners in templates.
66
+
مثل المكونات والخصائص ، توفر أسماء الأحداث تحويل تلقائي لحالة الأحرف. يمكن ملاحظة أننا أرسلنا حدث مكتوب بنمط سنام الجمل camelCase ، لكن يمكننا الاستماع له باستخدام مستمع مكتوب بنمط أسياخ الشواء kebab-case داخل المكون الأب. كما في [تسمية الخاصيات](/guide/components/props.html#prop-name-casing) ، نوصي باستخدام مستمعي أحداث بنمط kebab-case في القوالب.
66
67
67
-
:::tip
68
-
Unlike native DOM events, component emitted events do **not** bubble. You can only listen to the events emitted by a direct child component. If there is a need to communicate between sibling or deeply nested components, use an external event bus or a [global state management solution](/guide/scaling-up/state-management.html).
68
+
:::tip ملاحظة
69
+
على عكس أحداث DOM الأصلية، فإن أحداث المكونات المرسلة لا تنتشر عبر شجرة مكونات التطبيق. يمكنك الاستماع فقط إلى الأحداث المرسلة من المكون الابن المباشر. إذا كان هناك حاجة للتواصل بين المكونات الشقيقة أو المكونات المتداخلة بعمق، فاستخدم ناقل خارجي للأحداث أو [حلول إدارة الحالة العامة](/guide/scaling-up/state-management.html).
69
70
:::
70
71
71
-
## Event Arguments {#event-arguments}
72
+
## وسائط الحدث {#event-arguments}
72
73
73
-
It's sometimes useful to emit a specific value with an event. For example, we may want the `<BlogPost>`component to be in charge of how much to enlarge the text by. In those cases, we can pass extra arguments to `$emit` to provide this value:
74
+
في بعض الأحيان ، يكون من المفيد إرسال قيمة معينة مع الحدث. على سبيل المثال، قد نرغب في أن يكون المكون `<BlogPost>`مسؤولًا عن حجم تكبير النص. في هذه الحالات ، يمكننا إرسال وسائط إضافية إلى `emit$` لتوفير هذه القيمة:
74
75
75
76
```vue-html
76
77
<button @click="$emit('increaseBy', 1)">
77
-
Increase by 1
78
+
زيادة بـ 1
78
79
</button>
79
80
```
80
81
81
-
Then, when we listen to the event in the parent, we can use an inline arrow function as the listener, which allows us to access the event argument:
82
+
ثم، عندما نستمع إلى الحدث في المكون الأب، يمكننا استخدام الدالة السهمية السطرية كمستمع، والتي تسمح لنا بالوصول إلى وسيط الحدث المرسل:
82
83
83
84
```vue-html
84
85
<MyButton @increase-by="(n) => count += n" />
85
86
```
86
87
87
-
Or, if the event handler is a method:
88
+
أو، إذا كان معالج الحدث عبارة عن تابع:
88
89
89
90
```vue-html
90
91
<MyButton @increase-by="increaseCount" />
91
92
```
92
93
93
94
Then the value will be passed as the first parameter of that method:
94
95
96
+
ثم ستُمرَّر القيمة كأول وسيط لهذا التابع:
97
+
95
98
<divclass="options-api">
96
99
97
100
```js
@@ -113,13 +116,13 @@ function increaseCount(n) {
113
116
114
117
</div>
115
118
116
-
:::tip
117
-
All extra arguments passed to `$emit()` after the event name will be forwarded to the listener. For example, with `$emit('foo', 1, 2, 3)` the listener function will receive three arguments.
119
+
:::tip ملاحظة
120
+
تمرر جميع الوسائط الإضافية المرسلة عبر `()emit$` بعد اسم الحدث إلى المستمع. على سبيل المثال ، مع `emit('foo', 1, 2, 3)$` ستتلقى دالة المستمع ثلاثة وسائط.
A component can explicitly declare the events it will emit using the <spanclass="composition-api">[`defineEmits()`](/api/sfc-script-setup.html#defineprops-defineemits)macro</span><spanclass="options-api">[`emits`](/api/options-state.html#emits)option</span>:
125
+
يمكن للمكون التصريح بشكل واضح عن الأحداث التي سيقوم بإرسالها باستخدام <spanclass="composition-api"> التعليمة العامة [`()defineEmits`](/api/sfc-script-setup.html#defineprops-defineemits) </span><spanclass="options-api">خيار [`emits`](/api/options-state.html#emits) </span>:
The `$emit` method that we used in the `<template>`isn't accessible within the`<script setup>`section of a component, but `defineEmits()` returns an equivalent function that we can use instead:
135
+
`emit$` هو التابع الذي استخدمناه في `<template>`غير متاح داخل قسم`<script setup>`للمكون ، ولكن `()defineEmits` تعيد دالة مكافئة يمكننا استخدامها بدلاً من ذلك:
133
136
134
137
```vue
135
138
<script setup>
@@ -141,9 +144,9 @@ function buttonClick() {
141
144
</script>
142
145
```
143
146
144
-
The `defineEmits()` macro **cannot**be used inside a function, it must be placed directly within `<script setup>`, as in the example above.
147
+
التعليمة العامة `()defineEmits`**لا يمكن**استخدامها داخل دالة ، يجب وضعها مباشرة داخل `<script setup>` ، كما هو الحال في المثال أعلاه.
145
148
146
-
If you're using an explicit `setup`function instead of `<script setup>`, events should be declared using the [`emits`](/api/options-state.html#emits)option, and the `emit`function is exposed on the `setup()` context:
149
+
إذا كنت تستخدم الدالة `setup`بدلاً من `<script setup>` ، فيجب عليك الإعلان عن الأحداث باستخدام خيار [`emits`](/api/options-state.html#emits)، ويتم توفير التابع `emit`في سياق `()setup` كوسيط ثاني:
147
150
148
151
```js
149
152
exportdefault {
@@ -154,7 +157,7 @@ export default {
154
157
}
155
158
```
156
159
157
-
As with other properties of the `setup()` context, `emit`can safely be destructured:
160
+
كما هو الحال مع الخاصيات الأخرى في سياق `()setup` ، يمكن تفكيك `emit`بأمان:
158
161
159
162
```js
160
163
exportdefault {
@@ -176,22 +179,24 @@ export default {
176
179
177
180
</div>
178
181
179
-
The`emits`option also supports an object syntax, which allows us to perform runtime validation of the payload of the emitted events:
182
+
خيار`emits`يدعم أيضًا صيغة الكائن ، والتي تسمح لنا بتنفيذ التحقق من صحة الوسائط الممررة للأحداث المرسلة في وقت التشغيل :
180
183
181
184
<divclass="composition-api">
182
185
183
186
```vue
184
187
<script setup>
185
188
const emit = defineEmits({
186
189
submit(payload) {
187
-
// return `true` or `false` to indicate
188
-
// validation pass / fail
190
+
// اعد
191
+
//`true` أو `false`
192
+
// للإشارة إلى
193
+
// نجاح / فشل التحقق
189
194
}
190
195
})
191
196
</script>
192
197
```
193
198
194
-
If you are using TypeScript with`<script setup>`, it's also possible to declare emitted events using pure type annotations:
199
+
إذا كنت تستخدم TypeScript مع`<script setup>` ، فمن الممكن أيضًا تعريف الأحداث المرسلة باستخدام التوصيفات النوعية البحتة:
195
200
196
201
```vue
197
202
<script setup lang="ts">
@@ -202,7 +207,7 @@ const emit = defineEmits<{
202
207
</script>
203
208
```
204
209
205
-
More details: [Typing Component Emits](/guide/typescript/composition-api.html#typing-component-emits) <supclass="vt-badge ts" />
210
+
أكثر تفاصيل حول : [إضافة الأنواع إلى الأحداث المرسلة](/guide/typescript/composition-api.html#typing-component-emits) <supclass="vt-badge ts" />
206
211
207
212
</div>
208
213
<divclass="options-api">
@@ -211,43 +216,45 @@ More details: [Typing Component Emits](/guide/typescript/composition-api.html#ty
211
216
exportdefault {
212
217
emits: {
213
218
submit(payload) {
214
-
// return `true` or `false` to indicate
215
-
// validation pass / fail
219
+
// اعد
220
+
//`true` أو `false`
221
+
// للإشارة إلى
222
+
// نجاح / فشل التحقق
216
223
}
217
224
}
218
225
}
219
226
```
220
227
221
-
See also: [Typing Component Emits](/guide/typescript/options-api.html#typing-component-emits) <supclass="vt-badge ts" />
228
+
أكثر تفاصيل حول : [إضافة الأنواع إلى الأحداث المرسلة](/guide/typescript/options-api.html#typing-component-emits) <supclass="vt-badge ts" />
222
229
223
230
</div>
224
231
225
-
Although optional, it is recommended to define all emitted events in order to better document how a component should work. It also allows Vue to exclude known listeners from [fallthrough attributes](/guide/components/attrs.html#v-on-listener-inheritance), avoiding edge cases caused by DOM events manually dispatched by 3rd party code.
232
+
على الرغم من أن الأمر اختياري، إلا أنه ينصح بتعريف جميع الأحداث المرسلة من أجل توثيق جيد لكيفية عمل المكون. كما يسمح لـ Vue باستبعاد المستمعين المعروفين من [السمات المستترة](/guide/components/attrs.html#v-on-listener-inheritance) ، وتجنب الحالات القصوى الناتجة عن أحداث الـDOM الموزعة يدويا من المكتبات الخارجية.
226
233
227
-
:::tip
228
-
If a native event (e.g., `click`) is defined in the `emits`option, the listener will now only listen to component-emitted `click`events and no longer respond to native `click`events.
234
+
:::tip ملاحظة
235
+
إذا تم تعريف حدث أصلي (على سبيل المثال ، `click`) في خيار `emits`، فسينصت المستمع الآن فقط إلى أحداث `click`المنشأة من المكون ولن يستجيب لأحداث `click`الأصلية.
229
236
:::
230
237
231
-
## Events Validation {#events-validation}
238
+
## التحقق من صحة الأحداث {#events-validation}
232
239
233
-
Similar to prop type validation, an emitted event can be validated if it is defined with the object syntax instead of the array syntax.
240
+
مثلما هو الحال بالنسبة للتحقق من صحة نوع الخاصية ، يمكن التحقق من صحة الحدث المرسل إذا تم تعريفه باستخدام صيغة الكائن بدلاً من صيغة المصفوفة.
234
241
235
-
To add validation, the event is assigned a function that receives the arguments passed to the <spanclass="options-api">`this.$emit`</span><spanclass="composition-api">`emit`</span> call and returns a boolean to indicate whether the event is valid or not.
242
+
لإضافة التحقق ، يعطىالحدث دالة كقيمة والتي تتلقى الوسائط الممررة إلى الاستدعاء <spanclass="options-api">`this.$emit`</span><spanclass="composition-api">`emit`</span> وتعيد قيمة منطقية لتشير إلى صحة الحدث من عدمها.
236
243
237
244
<divclass="composition-api">
238
245
239
246
```vue
240
247
<script setup>
241
248
const emit = defineEmits({
242
-
// No validation
249
+
// لا يوجد تحقق
243
250
click: null,
244
251
245
-
// Validate submit event
252
+
// تحقق من حدث الإرسال
246
253
submit: ({ email, password }) => {
247
254
if (email && password) {
248
255
return true
249
256
} else {
250
-
console.warn('Invalid submit event payload!')
257
+
console.warn('وسائط حدث الإرسال غير صالحة!')
251
258
return false
252
259
}
253
260
}
@@ -265,15 +272,15 @@ function submitForm(email, password) {
0 commit comments