Skip to content
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

built-in-special-attributes #135

Merged
merged 24 commits into from
Dec 27, 2023
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
7add2e7
Update built-in-special-attributes.md
MMDShen Dec 24, 2023
1c1d956
Merge pull request #1 from MMDShen/MMDShen-patch-1
MMDShen Dec 24, 2023
810a386
Update src/api/built-in-special-attributes.md
MMDShen Dec 27, 2023
f056d79
Update src/api/built-in-special-attributes.md
MMDShen Dec 27, 2023
2e58225
Update src/api/built-in-special-attributes.md
MMDShen Dec 27, 2023
5a2e433
Update src/api/built-in-special-attributes.md
MMDShen Dec 27, 2023
e91f517
Update src/api/built-in-special-attributes.md
MMDShen Dec 27, 2023
152c649
Update src/api/built-in-special-attributes.md
MMDShen Dec 27, 2023
473f36f
Update src/api/built-in-special-attributes.md
MMDShen Dec 27, 2023
774c3a1
Update src/api/built-in-special-attributes.md
MMDShen Dec 27, 2023
c06ea63
Update src/api/built-in-special-attributes.md
MMDShen Dec 27, 2023
f0e01ae
Update src/api/built-in-special-attributes.md
MMDShen Dec 27, 2023
c3a31f4
Update src/api/built-in-special-attributes.md
MMDShen Dec 27, 2023
b02f476
Update src/api/built-in-special-attributes.md
MMDShen Dec 27, 2023
b1b7271
Update src/api/built-in-special-attributes.md
MMDShen Dec 27, 2023
059e9f4
Update src/api/built-in-special-attributes.md
MMDShen Dec 27, 2023
bd7981f
Update src/api/built-in-special-attributes.md
MMDShen Dec 27, 2023
a35741f
Update src/api/built-in-special-attributes.md
MMDShen Dec 27, 2023
87eaed0
Update src/api/built-in-special-attributes.md
MMDShen Dec 27, 2023
768cea6
Update src/api/built-in-special-attributes.md
MMDShen Dec 27, 2023
89ae6bc
Update src/api/built-in-special-attributes.md
MMDShen Dec 27, 2023
4241508
Update src/api/built-in-special-attributes.md
MMDShen Dec 27, 2023
7c00c70
Update src/api/built-in-special-attributes.md
MMDShen Dec 27, 2023
b91c3bf
Update src/api/built-in-special-attributes.md
MMDShen Dec 27, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 36 additions & 35 deletions src/api/built-in-special-attributes.md
Original file line number Diff line number Diff line change
@@ -1,60 +1,61 @@
# Built-in Special Attributes {#built-in-special-attributes}
# ویژگی‌های خاص ساخته شده {#built-in-special-attributes}

## key {#key}

The `key` special attribute is primarily used as a hint for Vue's virtual DOM algorithm to identify vnodes when diffing the new list of nodes against the old list.
ویژگی خاص `key` به عنوان یک راهنما برای الگوریتم DOM مجازی Vue استفاده می‌شود تا هنگام تفاوت‌یابی لیست جدید نودها با لیست قدیمی، vnodes را شناسایی کند.

- **Expects:** `number | string | symbol`
- **انتظارات:** `number | string | symbol`

- **Details**
- **جزئیات**

Without keys, Vue uses an algorithm that minimizes element movement and tries to patch/reuse elements of the same type in-place as much as possible. With keys, it will reorder elements based on the order change of keys, and elements with keys that are no longer present will always be removed / destroyed.
بدون Vue ، Key از یک الگوریتم استفاده می‌کند که حرکت عناصر را به حداقل می‌رساند و سعی می‌کند عناصر هم نوع را تا حد امکان در جای خود ترمیم/باز استفاده کند. با key، این عناصر را بر اساس تغییر ترتیب keyها مرتب می‌کند و عناصری که دارای `key`هایی هستند که دیگر وجود ندارند، همیشه حذف / نابود می‌شوند.

Children of the same common parent must have **unique keys**. Duplicate keys will cause render errors.
فرزندان یک والد مشترک باید دارای key های منحصر به فرد باشند. key های تکراری باعث خطاهای رندر می‌شوند.

The most common use case is combined with `v-for`:
رایج‌ترین مورد استفاده این ویژگی، همراه با `v-for` است:

```vue-html
<ul>
<li v-for="item in items" :key="item.id">...</li>
</ul>
```

MMDShen marked this conversation as resolved.
Show resolved Hide resolved
It can also be used to force replacement of an element/component instead of reusing it. This can be useful when you want to:
این ویژگی را میتوان برای اجبار جایگزینی یک عنصر/کامپوننت به جای باز استفاده از آن نیز استفاده کرد. این میتواند زمانی مفید باشد که شما بخواهید:

- Properly trigger lifecycle hooks of a component
- Trigger transitions
• به درستی هوک های چرخه حیات یک کامپوننت را فعال کنید

For example:
• ترنزیشن را فعال کنید

برای مثال:

```vue-html
<transition>
<span :key="text">{{ text }}</span>
</transition>
```

When `text` changes, the `<span>` will always be replaced instead of patched, so a transition will be triggered.
وقتی `text` تغییر کند، همیشه المنت `<span>` جایگزین می‌شود به جای اینکه صرفا متن آن تغییر کند، بنابراین ترنزیشین فعال می‌شود.

- **See also** [Guide - List Rendering - Maintaining State with `key`](/guide/essentials/list#maintaining-state-with-key)
- **همچنین ببینید** [راهنما - لیست رندرینگ - حفظ state با `key`](/guide/essentials/list#maintaining-state-with-key)

## ref {#ref}

Denotes a [template ref](/guide/essentials/template-refs).
یک [ارجاع از طریق تمپلیت](/guide/essentials/template-refs) را نشان می‌دهد.

- **Expects:** `string | Function`
- **انتظارات:** `string | Function`

- **Details**
- **جزئیات**

`ref` is used to register a reference to an element or a child component.
`ref` برای ثبت یک ارجاع به یک عنصر یا یک کامپوننت فرزند استفاده می‌شود.

In Options API, the reference will be registered under the component's `this.$refs` object:
در Option API ارجاع تحت آبجکت `this.$refs‎` کامپوننت ثبت می‌شود:

```vue-html
<!-- stored as this.$refs.p -->
<p ref="p">hello</p>
```

In Composition API, the reference will be stored in a ref with matching name:
در Composition API، ارجاع در یک ref با نام منطبق ذخیره می‌شود:

```vue
<script setup>
Expand All @@ -68,42 +69,42 @@ Denotes a [template ref](/guide/essentials/template-refs).
</template>
```

If used on a plain DOM element, the reference will be that element; if used on a child component, the reference will be the child component instance.
اگر از این ویژگی روی یک عنصر DOM ساده استفاده شود، ارجاع همان عنصر خواهد بود؛ اگر روی یک کامپوننت فرزند استفاده شود، ارجاع نمونه ساخته شده از کامپوننت فرزند خواهد بود.

Alternatively `ref` can accept a function value which provides full control over where to store the reference:
به طور جایگزین `ref` میتواند یک مقدار تابعی را بپذیرد که کنترل کاملی روی اینکه کجا رفرنس دریافت شده را ذخیره کنید، فراهم می‌کند:

```vue-html
<ChildComponent :ref="(el) => child = el" />
```

An important note about the ref registration timing: because the refs themselves are created as a result of the render function, you must wait until the component is mounted before accessing them.
یک نکته مهم در مورد زمان ثبت ref این است که چون ref ها خودشان به عنوان نتیجه تابع رندر ایجاد می‌شوند، شما باید تا زمانی که کامپوننت mount شود، صبر کنید تا به آنها دسترسی پیدا کنید.

`this.$refs` is also non-reactive, therefore you should not attempt to use it in templates for data-binding.
`this.$refs` همچنین reactive نیست، بنابراین شما نباید سعی کنید که از آن در تمپلیت‌ها برای اتصال دادن داده استفاده کنید.

- **See also**
- [Guide - Template Refs](/guide/essentials/template-refs)
- [Guide - Typing Template Refs](/guide/typescript/composition-api#typing-template-refs) <sup class="vt-badge ts" />
- [Guide - Typing Component Template Refs](/guide/typescript/composition-api#typing-component-template-refs) <sup class="vt-badge ts" />
- **همچنین ببینید**
- [راهنما - تمپلیت مراجع](/guide/essentials/template-refs)
- [راهنما - نوع تمپلیت مراجع](/guide/typescript/composition-api#typing-template-refs) <sup class="vt-badge ts" />
- [راهنما - نوع کامپوننت تمپلیت مراجع](/guide/typescript/composition-api#typing-component-template-refs) <sup class="vt-badge ts" />

## is {#is}

Used for binding [dynamic components](/guide/essentials/component-basics#dynamic-components).
برای اتصال [کامپوننت های داینامیک](/guide/essentials/component-basics#dynamic-components) استفاده میشود.

- **Expects:** `string | Component`
- **انتظارات:** `string | Component`

- **Usage on native elements** <sup class="vt-badge">3.1+</sup>
- **استفاده در عناصر بومی** <sup class="vt-badge">3.1+</sup>

When the `is` attribute is used on a native HTML element, it will be interpreted as a [Customized built-in element](https://html.spec.whatwg.org/multipage/custom-elements.html#custom-elements-customized-builtin-example), which is a native web platform feature.
وقتی ویژگی `is` روی یک عنصر HTML بومی استفاده شود، به عنوان یک <a href="https://html.spec.whatwg.org/multipage/custom-elements.html#custom-elements-customized-builtin-example">عنصر سفارشی ساخته شده</a> تفسیر می‌شود، که یک ویژگی بومی پلتفرم وب است.

There is, however, a use case where you may need Vue to replace a native element with a Vue component, as explained in [in-DOM Template Parsing Caveats](/guide/essentials/component-basics#in-dom-template-parsing-caveats). You can prefix the value of the `is` attribute with `vue:` so that Vue will render the element as a Vue component instead:
اما یک مورد استفاده وجود دارد که شما ممکن است نیاز داشته باشید که Vue یک عنصر بومی را با یک کامپوننت Vue جایگزین کند، که در [محدودیت‌های تجزیه تمپلیت در DOM](/guide/essentials/component-basics#in-dom-template-parsing-caveats) توضیح داده شده است. شما میتوانید مقدار ویژگی `is` را با `vue:‎` پیشوند کنید تا Vue عنصر را به عنوان یک کامپوننت Vue رندر کند:

```vue-html
<table>
<tr is="vue:my-row-component"></tr>
</table>
```

- **See also**
- **همچنین ببینید**

- [Built-in Special Element - `<component>`](/api/built-in-special-elements#component)
- [Dynamic Components](/guide/essentials/component-basics#dynamic-components)
- [عنصر خاص ساخته شده - `<component>`](/api/built-in-special-elements#component)
- [کامپوننت های داینامیک](/guide/essentials/component-basics#dynamic-components)