Skip to content

Commit 7e1b39a

Browse files
author
ntepluhina
committed
feat: finished declarative rendering
1 parent 385e60c commit 7e1b39a

File tree

3 files changed

+119
-1
lines changed

3 files changed

+119
-1
lines changed

docs/.vuepress/components/intro-1.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" class="demo">
3+
{{ message }}
4+
</div>
5+
</template>
6+
7+
<script>
8+
export default {
9+
data() {
10+
return {
11+
message: 'Hello Vue!'
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-2.vue

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<template>
2+
<div id="app-2" class="demo">
3+
<span v-bind:title="message">
4+
Hover your mouse over me for a few seconds to see my dynamically bound title!
5+
</span>
6+
</div>
7+
</template>
8+
9+
<script>
10+
export default {
11+
data() {
12+
return {
13+
message: 'You loaded this page on ' + new Date().toLocaleString()
14+
}
15+
},
16+
}
17+
</script>
18+
19+
<style scoped>
20+
.demo {
21+
border: 1px solid #eee;
22+
border-radius: 2px;
23+
padding: 25px 35px;
24+
margin-top: 1em;
25+
margin-bottom: 40px;
26+
user-select: none;
27+
overflow-x: auto;
28+
}
29+
30+
span {
31+
margin-bottom: 0;
32+
margin-top: 0;
33+
}
34+
</style>

docs/guide/introduction.md

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,61 @@ or:
3434

3535
The [Installation](installation.md) page provides more options of installing Vue. Note: We **do not** recommend that beginners start with `vue-cli`, especially if you are not yet familiar with Node.js-based build tools.
3636

37-
If you prefer something more interactive, you can also check out [this tutorial series on Scrimba](https://scrimba.com/g/gvuedocs), which gives you a mix of screencast and code playground that you can pause and play around with anytime.
37+
If you prefer something more interactive, you can also check out [this tutorial series on Scrimba](https://scrimba.com/g/gvuedocs), which gives you a mix of screencast and code playground that you can pause and play around with anytime.
38+
39+
## Declarative Rendering
40+
41+
At the core of Vue.js is a system that enables us to declaratively render data to the DOM using straightforward template syntax:
42+
43+
``` html
44+
<div id="app">
45+
{{ message }}
46+
</div>
47+
```
48+
``` js
49+
const app = new Vue({
50+
el: '#app',
51+
data() {
52+
return {
53+
message: 'Hello Vue!'
54+
}
55+
}
56+
})
57+
```
58+
<intro-1 />
59+
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>
69+
70+
In addition to text interpolation, we can also bind element attributes like this:
71+
72+
``` html
73+
<div id="app-2">
74+
<span v-bind:title="message">
75+
Hover your mouse over me for a few seconds
76+
to see my dynamically bound title!
77+
</span>
78+
</div>
79+
```
80+
``` js
81+
const app2 = new Vue({
82+
el: '#app-2',
83+
data() {
84+
return {
85+
message: 'You loaded this page on ' + new Date().toLocaleString()
86+
}
87+
}
88+
})
89+
```
90+
<intro-2 />
91+
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."
92+
93+
If you open up your JavaScript console again and enter `app2.message = 'some new message'`, you'll once again see that the bound HTML - in this case the `title` attribute - has been updated.
94+

0 commit comments

Comments
 (0)