Skip to content

Commit a12372b

Browse files
author
ntepluhina
committed
Added handling user input
1 parent 5afa4c4 commit a12372b

File tree

4 files changed

+107
-8
lines changed

4 files changed

+107
-8
lines changed

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<template>
2+
<div id="app-5" class="demo">
3+
<p>{{ message }}</p>
4+
<button v-on:click="reverseMessage">Reverse Message</button>
5+
</div>
6+
</template>
7+
8+
<script>
9+
export default {
10+
data() {
11+
return {
12+
message: 'Hello Vue.js!'
13+
}
14+
},
15+
methods: {
16+
reverseMessage: function () {
17+
this.message = this.message.split('').reverse().join('')
18+
}
19+
}
20+
}
21+
</script>

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<template>
2+
<div id="app-6" class="demo">
3+
<p>{{ message }}</p>
4+
<input v-model="message">
5+
</div>
6+
</template>
7+
8+
<script>
9+
export default {
10+
data() {
11+
return {
12+
message: 'Hello Vue!'
13+
}
14+
},
15+
}
16+
</script>

docs/.vuepress/styles/index.styl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
11
.theme-default-content:not(.custom) {
22
max-width 960px
3+
}
4+
5+
.demo {
6+
font-family: sans-serif;
7+
border: 1px solid #eee;
8+
border-radius: 2px;
9+
padding: 20px 30px;
10+
margin-top: 1em;
11+
margin-bottom: 40px;
12+
user-select: none;
13+
overflow-x: auto;
314
}

docs/guide/introduction.md

Lines changed: 59 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -109,15 +109,66 @@ There are quite a few other directives, each with its own special functionality.
109109
</div>
110110
```
111111
``` js
112-
var app4 = new Vue({
112+
const app4 = new Vue({
113113
el: '#app-4',
114-
data: {
115-
todos: [
116-
{ text: 'Learn JavaScript' },
117-
{ text: 'Learn Vue' },
118-
{ text: 'Build something awesome' }
119-
]
114+
data() {
115+
return {
116+
todos: [
117+
{ text: 'Learn JavaScript' },
118+
{ text: 'Learn Vue' },
119+
{ text: 'Build something awesome' }
120+
]
121+
}
122+
}
123+
})
124+
```
125+
<intro-4/>
126+
127+
## Handling User Input
128+
129+
To let users interact with your app, we can use the `v-on` directive to attach event listeners that invoke methods on our Vue instances:
130+
131+
``` html
132+
<div id="app-5">
133+
<p>{{ message }}</p>
134+
<button v-on:click="reverseMessage">Reverse Message</button>
135+
</div>
136+
```
137+
``` js
138+
constapp5 = new Vue({
139+
el: '#app-5',
140+
data() {
141+
return {
142+
message: 'Hello Vue.js!'
143+
}
144+
},
145+
methods: {
146+
reverseMessage() {
147+
this.message = this.message.split('').reverse().join('')
148+
}
149+
}
150+
})
151+
```
152+
<intro-5/>
153+
154+
Note that in this method we update the state of our app without touching the DOM - all DOM manipulations are handled by Vue, and the code you write is focused on the underlying logic.
155+
156+
Vue also provides the `v-model` directive that makes two-way binding between form input and app state a breeze:
157+
158+
``` html
159+
<div id="app-6">
160+
<p>{{ message }}</p>
161+
<input v-model="message">
162+
</div>
163+
```
164+
``` js
165+
var app6 = new Vue({
166+
el: '#app-6',
167+
data() {
168+
return {
169+
message: 'Hello Vue!'
170+
}
120171
}
121172
})
122173
```
123-
<intro-4/>
174+
<intro-6/>

0 commit comments

Comments
 (0)