-
Notifications
You must be signed in to change notification settings - Fork 0
/
first.html
46 lines (39 loc) · 1.19 KB
/
first.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<!DOCTYPE html>
<html>
<head>
<title>First Vue Code</title>
</head>
<body>
<div id="root">
<ul>
<li v-for="name in names" v-text="name">
</li>
</ul>
<input id="input" type="text" v-model="newName">
<button @click="addName">Add Name</button>
</div>
<script src="https://unpkg.com/vue@2.1.3/dist/vue.js"></script>
<script>
var app=new Vue({
el: '#root',
data:{
newName:'',
names:['Joe','Mary','Jane','Jack']
} ,
methods: {
addName() {
this.names.push(this.newName);
this.newName='';
}
},
mounted() {
document.querySelector('#button').addEventListener('click',() =>{
let name=document.querySelector('#input');
app.names.push(name.value);
name.value='';
});
}
});
</script>
</body>
</html>