1
0
mirror of https://github.com/kamranahmedse/developer-roadmap.git synced 2025-08-01 06:50:26 +02:00

Added content to some Vue topics. (#7127)

* Added v-bind description

* Added v-for description

* Added v-text description

* Added v-html description

* Added v-once description

* Added v-pre description

* Added v-else-if description
This commit is contained in:
sickpoitew
2024-09-16 15:08:19 +02:00
committed by GitHub
parent 6130f16b23
commit 8dd03f0272
7 changed files with 122 additions and 7 deletions

View File

@@ -1 +1,21 @@
# v-bind
# v-bind
The `v-bind` directive dynamically binds an HTML attribute to data.
The shorthand for this directive is `:`
Example:
```vue
<script setup>
import { ref } from 'vue';
const image_url = ref("path/to/image.png")
</script>
<template>
<img :src="image_url" />
</template>
```
Visit the following resources for more information:
- [@official@v-bind documentation](https://vuejs.org/api/built-in-directives.html#v-bind)

View File

@@ -1 +1,6 @@
# v-else-if
# v-else-if
This directive is used to add additional conditions to a v-if and v-else block.
Visit the following resources to learn more:
- [@official@v-else-if Documentation](https://vuejs.org/api/built-in-directives.html#v-else-if)

View File

@@ -1 +1,25 @@
# v-for
# v-for
The `v-for` directive is used to render an HTML element, a block of elements, or even a component based on an array, an object, or a set number of times.
When using this directive it is important to assign a unique key to each item to avoid issues and improve perfomance.
This directive follows the `item in items` syntax.
Example:
```vue
<script setup>
import { ref } from 'vue';
const foods = ref([
{id: 1, name: "apple"},
{id: 2, name: "pear"},
{id: 3, name: "pizza"}
]);
</script>
<template>
<p v-for="food in foods" :key="food.id">{{ food.name }}</p>
</template>
```
Visit the following resources to learn more:
- [@official@v-for documentation](https://vuejs.org/guide/essentials/list#v-for)

View File

@@ -1 +1,14 @@
# v-html
# v-html
The `v-thml` directive is similar to the `v-text` directive, but the difference is that `v-html` renders its content as HTML. This means that if you pass an HTML element it will be rendered as an element and not plain text. Since the content is render as HTMl, it can pose a security risk if the content contains malicius JavaScript code. For this reason you should never use this directive in combination with user input, unless the input is first properly sanitized.
Example:
```vue
<template>
<p v-html="'<h1>Text</h1>'"></p>
</template>
```
Visit the following resources to learn more:
- [@official@v-html documentation](https://vuejs.org/api/built-in-directives.html#v-html)

View File

@@ -1 +1,21 @@
# v-once
# v-once
The `v-once` directive makes an HTML element render only once, skipping every future update.
Example:
```vue
<script setup>
import { ref } from 'vue';
const input = ref("Some Text");
</script>
<template>
<input v-model="input">
<p v-once>{{ input }}</p>
</template>
```
In this example the **p** element will not change its text even if the input variable is changed through the **input** element.
Visit the following resources to learn more:
- [@official@v-once documentation](https://vuejs.org/api/built-in-directives.html#v-once)

View File

@@ -1 +1,20 @@
# v-pre
# v-pre
The `v-pre` directive makes an element render its content as-is, skipping its compilation. The most common use case is when displaying raw mustache syntax.
Example:
```vue
<script setup>
import { ref } from 'vue';
const text = ref("Some Text")
</script>
<template>
<p v-pre >{{ text }}</p>
</template>
```
The **p** element will display: `{{ text }}` and not `Some Text` because the compilation is skipped.
Visit the following resources to learn more:
- [@official@v-pre Documentation](https://vuejs.org/api/built-in-directives.html#v-pre)

View File

@@ -1 +1,15 @@
# v-text
# v-text
The `v-text` directive is used to set the textContent property of an element. It's important to note that when using this directive it will overwrite the HTML content inside the element.
The expected input is a string, so it's important to wrap any text in single quotes.
Example:
```vue
<template>
<p v-text="'I am some text'"></p>
</template>
```
Visit the following resources to learn more:
- [@official@v-text documentation](https://vuejs.org/api/built-in-directives.html#v-text)