-
Notifications
You must be signed in to change notification settings - Fork 303
/
49.名称案例-方式2.html
54 lines (48 loc) · 1.65 KB
/
49.名称案例-方式2.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
47
48
49
50
51
52
53
54
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<script src="./lib/vue.js"></script>
</head>
<body>
<div id="app">
<!--1 我们要监听到文本框数据的改变, 这样才知道什么时候去拼接出一个fullName-->
<!--2 如何监听到文本框数据的改变 keyup事件-->
<!---->
<input type="text" v-model="firstName" > +
<input type="text" v-model="lastName" > =
<input type="text" v-model="fullName">
</div>
<script>
var vm = new Vue({
el: '#app',
data: {
firstName: '',
lastName: '',
fullName: '',
},
methods: {
getFullName() {
this.fullName = this.firstName + ' ' + this.lastName
},
getLastName() {
this.fullName = this.firstName + ' ' + this.lastName
}
},
watch: {
//使用这个而属性可以监听data中指定数据的变化,然后触发这个watch对应的function函数
firstName: function(newVal, oldVal){
//this.fullName = this.firstName + ' ' + this.lastName
//this.fullName = newVal + ' ' +this.lastName
},
lastName: function(newVal){
this.fullName = this.firstName + ' ' +newVal
},
},
})
</script>
</body>
</html>