Skip to content

Commit 5afa4c4

Browse files
author
ntepluhina
committed
feat: finished conditionals
1 parent 43077fa commit 5afa4c4

File tree

4 files changed

+105
-9
lines changed

4 files changed

+105
-9
lines changed

docs/.vuepress/components/intro-3.vue

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<template>
2+
<div id="app-3" class="demo">
3+
<span v-if="seen">Now you see me</span>
4+
</div>
5+
</template>
6+
7+
<script>
8+
export default {
9+
data() {
10+
return {
11+
seen: true
12+
}
13+
},
14+
}
15+
</script>
16+
17+
<style scoped>
18+
.demo {
19+
border: 1px solid #eee;
20+
border-radius: 2px;
21+
padding: 25px 35px;
22+
margin-top: 1em;
23+
margin-bottom: 40px;
24+
user-select: none;
25+
overflow-x: auto;
26+
}
27+
</style>

docs/.vuepress/components/intro-4.vue

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<template>
2+
<div id="app-4" class="demo">
3+
<ol>
4+
<li v-for="todo in todos">
5+
{{ todo.text }}
6+
</li>
7+
</ol>
8+
</div>
9+
</template>
10+
11+
<script>
12+
export default {
13+
data() {
14+
return {
15+
todos: [
16+
{ text: 'Learn JavaScript' },
17+
{ text: 'Learn Vue' },
18+
{ text: 'Build something awesome' }
19+
]
20+
}
21+
},
22+
}
23+
</script>
24+
25+
<style scoped>
26+
.demo {
27+
border: 1px solid #eee;
28+
border-radius: 2px;
29+
padding: 25px 35px;
30+
margin-top: 1em;
31+
margin-bottom: 40px;
32+
user-select: none;
33+
overflow-x: auto;
34+
}
35+
</style>

docs/.vuepress/styles/index.styl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.theme-default-content:not(.custom) {
2+
max-width 960px
3+
}

docs/guide/introduction.md

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,7 @@ const app = new Vue({
5757
```
5858
<intro-1 />
5959

60-
We have already created our very first Vue app! This looks pretty similar to rendering a string template, but Vue has done a lot of work under the hood. The data and the DOM are now linked, and everything is now **reactive**. How do we know? Change the `message` property in the code snippet below to a different value. You the rendered example update accordingly:
61-
62-
<iframe
63-
src="https://codesandbox.io/embed/vue-basic-example-buthm?autoresize=1&fontsize=14&hidenavigation=1&moduleview=1&theme=dark"
64-
style="width:100%; height:500px; border:0; border-radius: 4px; overflow:hidden;"
65-
title="Vue basic example"
66-
allow="geolocation; microphone; camera; midi; vr; accelerometer; gyroscope; payment; ambient-light-sensor; encrypted-media; usb"
67-
sandbox="allow-modals allow-forms allow-popups allow-scripts allow-same-origin"
68-
></iframe>
60+
We have already created our very first Vue app! This looks pretty similar to rendering a string template, but Vue has done a lot of work under the hood. The data and the DOM are now linked, and everything is now **reactive**. How do we know? Change the `message` property in the code snippet below to a different value. You the rendered example update accordingly: ![placeholder sandbox link](https://codesandbox.io/s/xenodochial-meninsky-rxlt4)
6961

7062
In addition to text interpolation, we can also bind element attributes like this:
7163

@@ -90,3 +82,42 @@ const app2 = new Vue({
9082
<intro-2 />
9183
Here we are encountering something new. The `v-bind` attribute you are seeing is called a **directive**. Directives are prefixed with `v-` to indicate that they are special attributes provided by Vue, and as you may have guessed, they apply special reactive behavior to the rendered DOM. Here, it is basically saying "keep this element's `title` attribute up-to-date with the `message` property on the Vue instance."
9284

85+
## Conditionals and Loops
86+
87+
It's easy to toggle the presence of an element, too:
88+
89+
``` html
90+
<div id="app-3">
91+
<span v-if="seen">Now you see me</span>
92+
</div>
93+
```
94+
<intro-3/>
95+
96+
This example demonstrates that we can bind data to not only text and attributes, but also the **structure** of the DOM. Moreover, Vue also provides a powerful transition effect system that can automatically apply [transition effects](TODO) when elements are inserted/updated/removed by Vue.
97+
98+
You can change `seen` from `true` to `false` in the sandbox below to check the effect: https://codesandbox.io/s/basic-conditional-rendering-eptpp
99+
100+
There are quite a few other directives, each with its own special functionality. For example, the `v-for` directive can be used for displaying a list of items using the data from an Array:
101+
102+
``` html
103+
<div id="app-4">
104+
<ol>
105+
<li v-for="todo in todos">
106+
{{ todo.text }}
107+
</li>
108+
</ol>
109+
</div>
110+
```
111+
``` js
112+
var app4 = new Vue({
113+
el: '#app-4',
114+
data: {
115+
todos: [
116+
{ text: 'Learn JavaScript' },
117+
{ text: 'Learn Vue' },
118+
{ text: 'Build something awesome' }
119+
]
120+
}
121+
})
122+
```
123+
<intro-4/>

0 commit comments

Comments
 (0)