Skip to content

Commit e96a07d

Browse files
Merge pull request vuejs#60 from boussadjra/feat/lifecycle
fix vuejs#20 vuejs#21 vuejs#23 vuejs#7 vuejs#12 vuejs#15 vuejs#17
2 parents edb5008 + 1ac8d3d commit e96a07d

File tree

9 files changed

+582
-505
lines changed

9 files changed

+582
-505
lines changed

Diff for: .vitepress/config.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ export const sidebar: ThemeConfig['sidebar'] = {
197197
{ text: 'الأحداث', link: '/guide/components/events' },
198198
{ text: 'الخاصية v-model', link: '/guide/components/v-model' },
199199
{
200-
text: 'السمات الإحتياطية',
200+
text: 'السمات المستترة',
201201
link: '/guide/components/attrs'
202202
},
203203
{ text: 'الفتحات', link: '/guide/components/slots' },
@@ -662,7 +662,7 @@ export default defineConfigWithTheme<ThemeConfig>({
662662
],
663663

664664
editLink: {
665-
repo: 'vuejs/docs-ar',
665+
repo: 'Abdelaziz18003/vuejs-docs-ar',//TODO - change to vuejs/docs-ar when ready
666666
text: 'عدل هذه الصفحة على GitHub'
667667
},
668668

Diff for: glossary.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
| conditional | شرطي |
3939
| list | قائمة |
4040
| key | مفتاح |
41-
| slot | مدخل |
41+
| slot | منفذ/مدخل |
4242
| ref | مرجع |
4343
| dependency | اعتمادية |
4444
| reactivity | (كإسم للمفهوم) تفاعلية |
@@ -62,3 +62,9 @@
6262
| unwrap | فك |
6363
| lazy | خامل |
6464
| index | مؤشر |
65+
| layout | نسق / تخطيط |
66+
| placeholder | عنصر/محتوى نائب |
67+
| implementation | الشيفرة التنفيذية |
68+
| tree-shaking | التجزئة الشجرية |
69+
| macro | تعليمة عامة |
70+
| bus | ناقل |

Diff for: src/guide/components/events.md

+52-45
Original file line numberDiff line numberDiff line change
@@ -17,26 +17,27 @@ if (typeof window !== 'undefined') {
1717
}
1818
}
1919
</script>
20-
# Component Events {#component-events}
2120

22-
> This page assumes you've already read the [Components Basics](/guide/essentials/component-basics). Read that first if you are new to components.
21+
# أحداث المكونات {#component-events}
22+
23+
> لقراءة هذه الصفحة يجب عليك أولا الاطلاع على [أساسيات المكونات](/guide/essentials/component-basics). ثم العودة إلى هنا.
2324
2425
<div class="options-api">
25-
<VueSchoolLink href="https://vueschool.io/lessons/defining-custom-events-emits" title="Free Vue.js Lesson on Defining Custom Events"/>
26+
<VueSchoolLink href="https://vueschool.io/lessons/defining-custom-events-emits" title="درس Vue.js مجاني حول الأحداث المخصصة"/>
2627
</div>
2728

28-
## Emitting and Listening to Events {#emitting-and-listening-to-events}
29+
## الإرسال والاستماع للأحداث {#emitting-and-listening-to-events}
2930

30-
A component can emit custom events directly in template expressions (e.g. in a `v-on` handler) using the built-in `$emit` method:
31+
يمكن للمكون إرسال أحداث مخصصة مباشرة في تعبيرات القالب (على سبيل المثال ، في معالج `v-on`) باستخدام التابع المدمج `emit$`:
3132

3233
```vue-html
3334
<!-- MyComponent -->
34-
<button @click="$emit('someEvent')">click me</button>
35+
<button @click="$emit('someEvent')">انفر الزر</button>
3536
```
3637

3738
<div class="options-api">
3839

39-
The `$emit()` method is also available on the component instance as `this.$emit()`:
40+
التابع `$emit()` متوفر أيضًا على نسخة المكون باستخدام `this.$emit()`:
4041

4142
```js
4243
export default {
@@ -50,48 +51,50 @@ export default {
5051

5152
</div>
5253

53-
The parent can then listen to it using `v-on`:
54+
المكون الأب يمكنه الاستماع لها باستخدام `v-on`:
5455

5556
```vue-html
5657
<MyComponent @some-event="callback" />
5758
```
5859

59-
The `.once` modifier is also supported on component event listeners:
60+
المعدل `.once` مدعوم أيضًا على مستمعي أحداث المكون:
6061

6162
```vue-html
6263
<MyComponent @some-event.once="callback" />
6364
```
6465

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 في القوالب.
6667

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).
6970
:::
7071

71-
## Event Arguments {#event-arguments}
72+
## وسائط الحدث {#event-arguments}
7273

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$` لتوفير هذه القيمة:
7475

7576
```vue-html
7677
<button @click="$emit('increaseBy', 1)">
77-
Increase by 1
78+
زيادة بـ 1
7879
</button>
7980
```
8081

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+
ثم، عندما نستمع إلى الحدث في المكون الأب، يمكننا استخدام الدالة السهمية السطرية كمستمع، والتي تسمح لنا بالوصول إلى وسيط الحدث المرسل:
8283

8384
```vue-html
8485
<MyButton @increase-by="(n) => count += n" />
8586
```
8687

87-
Or, if the event handler is a method:
88+
أو، إذا كان معالج الحدث عبارة عن تابع:
8889

8990
```vue-html
9091
<MyButton @increase-by="increaseCount" />
9192
```
9293

9394
Then the value will be passed as the first parameter of that method:
9495

96+
ثم ستُمرَّر القيمة كأول وسيط لهذا التابع:
97+
9598
<div class="options-api">
9699

97100
```js
@@ -113,13 +116,13 @@ function increaseCount(n) {
113116

114117
</div>
115118

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)$` ستتلقى دالة المستمع ثلاثة وسائط.
118121
:::
119122

120-
## Declaring Emitted Events {#declaring-emitted-events}
123+
## التصريح بالأحداث المرسلة {#declaring-emitted-events}
121124

122-
A component can explicitly declare the events it will emit using the <span class="composition-api">[`defineEmits()`](/api/sfc-script-setup.html#defineprops-defineemits) macro</span><span class="options-api">[`emits`](/api/options-state.html#emits) option</span>:
125+
يمكن للمكون التصريح بشكل واضح عن الأحداث التي سيقوم بإرسالها باستخدام <span class="composition-api"> التعليمة العامة [`()defineEmits`](/api/sfc-script-setup.html#defineprops-defineemits) </span><span class="options-api">خيار [`emits`](/api/options-state.html#emits) </span>:
123126

124127
<div class="composition-api">
125128

@@ -129,7 +132,7 @@ defineEmits(['inFocus', 'submit'])
129132
</script>
130133
```
131134

132-
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` تعيد دالة مكافئة يمكننا استخدامها بدلاً من ذلك:
133136

134137
```vue
135138
<script setup>
@@ -141,9 +144,9 @@ function buttonClick() {
141144
</script>
142145
```
143146

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>` ، كما هو الحال في المثال أعلاه.
145148

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` كوسيط ثاني:
147150

148151
```js
149152
export default {
@@ -154,7 +157,7 @@ export default {
154157
}
155158
```
156159

157-
As with other properties of the `setup()` context, `emit` can safely be destructured:
160+
كما هو الحال مع الخاصيات الأخرى في سياق `()setup` ، يمكن تفكيك `emit` بأمان:
158161

159162
```js
160163
export default {
@@ -176,22 +179,24 @@ export default {
176179

177180
</div>
178181

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` يدعم أيضًا صيغة الكائن ، والتي تسمح لنا بتنفيذ التحقق من صحة الوسائط الممررة للأحداث المرسلة في وقت التشغيل :
180183

181184
<div class="composition-api">
182185

183186
```vue
184187
<script setup>
185188
const emit = defineEmits({
186189
submit(payload) {
187-
// return `true` or `false` to indicate
188-
// validation pass / fail
190+
// اعد
191+
//`true` أو `false`
192+
// للإشارة إلى
193+
// نجاح / فشل التحقق
189194
}
190195
})
191196
</script>
192197
```
193198

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>` ، فمن الممكن أيضًا تعريف الأحداث المرسلة باستخدام التوصيفات النوعية البحتة:
195200

196201
```vue
197202
<script setup lang="ts">
@@ -202,7 +207,7 @@ const emit = defineEmits<{
202207
</script>
203208
```
204209

205-
More details: [Typing Component Emits](/guide/typescript/composition-api.html#typing-component-emits) <sup class="vt-badge ts" />
210+
أكثر تفاصيل حول : [إضافة الأنواع إلى الأحداث المرسلة](/guide/typescript/composition-api.html#typing-component-emits) <sup class="vt-badge ts" />
206211

207212
</div>
208213
<div class="options-api">
@@ -211,43 +216,45 @@ More details: [Typing Component Emits](/guide/typescript/composition-api.html#ty
211216
export default {
212217
emits: {
213218
submit(payload) {
214-
// return `true` or `false` to indicate
215-
// validation pass / fail
219+
// اعد
220+
//`true` أو `false`
221+
// للإشارة إلى
222+
// نجاح / فشل التحقق
216223
}
217224
}
218225
}
219226
```
220227

221-
See also: [Typing Component Emits](/guide/typescript/options-api.html#typing-component-emits) <sup class="vt-badge ts" />
228+
أكثر تفاصيل حول : [إضافة الأنواع إلى الأحداث المرسلة](/guide/typescript/options-api.html#typing-component-emits) <sup class="vt-badge ts" />
222229

223230
</div>
224231

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 الموزعة يدويا من المكتبات الخارجية.
226233

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` الأصلية.
229236
:::
230237

231-
## Events Validation {#events-validation}
238+
## التحقق من صحة الأحداث {#events-validation}
232239

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+
مثلما هو الحال بالنسبة للتحقق من صحة نوع الخاصية ، يمكن التحقق من صحة الحدث المرسل إذا تم تعريفه باستخدام صيغة الكائن بدلاً من صيغة المصفوفة.
234241

235-
To add validation, the event is assigned a function that receives the arguments passed to the <span class="options-api">`this.$emit`</span><span class="composition-api">`emit`</span> call and returns a boolean to indicate whether the event is valid or not.
242+
لإضافة التحقق ، يعطىالحدث دالة كقيمة والتي تتلقى الوسائط الممررة إلى الاستدعاء <span class="options-api">`this.$emit`</span><span class="composition-api">`emit`</span> وتعيد قيمة منطقية لتشير إلى صحة الحدث من عدمها.
236243

237244
<div class="composition-api">
238245

239246
```vue
240247
<script setup>
241248
const emit = defineEmits({
242-
// No validation
249+
// لا يوجد تحقق
243250
click: null,
244251
245-
// Validate submit event
252+
// تحقق من حدث الإرسال
246253
submit: ({ email, password }) => {
247254
if (email && password) {
248255
return true
249256
} else {
250-
console.warn('Invalid submit event payload!')
257+
console.warn('وسائط حدث الإرسال غير صالحة!')
251258
return false
252259
}
253260
}
@@ -265,15 +272,15 @@ function submitForm(email, password) {
265272
```js
266273
export default {
267274
emits: {
268-
// No validation
275+
// لا يوجد تحقق
269276
click: null,
270277

271-
// Validate submit event
278+
// تحقق من حدث الإرسال
272279
submit: ({ email, password }) => {
273280
if (email && password) {
274281
return true
275282
} else {
276-
console.warn('Invalid submit event payload!')
283+
console.warn('وسائط حدث الإرسال غير صالحة!')
277284
return false
278285
}
279286
}

0 commit comments

Comments
 (0)