forked from sunseekers/Vue2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwatch.html
44 lines (43 loc) · 994 Bytes
/
watch.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>wacth 的使用</title>
<meta name="description" content="">
<meta name="keywords" content="">
<link href="" rel="stylesheet">
</head>
<body>
<div id='app'>
<input type="text" v-model='searchQuery'>
<p v-if='isSearch' >search...</p>
<div v-else >
<ul>
<li v-for='(item,index) in items' v-cloak>{{ item }}</li>
</ul>
</div>
</div>
<script type="text/javascript" src='js/vue.min.js'></script>
<script>
let vm=new Vue({
el:"#app",
data:{
searchQuery:'search',
isSearch:true,
items:[]
},
watch:{
searchQuery:function(query){
this.isSearch=false;
this.items.push(query);
}
}
});
//$watch
vm.$watch('searchQuery',function(){
alert(1);
})
</script>
</body>
</html>