forked from sunseekers/Vue2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdirective.html
More file actions
46 lines (43 loc) · 844 Bytes
/
Copy pathdirective.html
File metadata and controls
46 lines (43 loc) · 844 Bytes
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>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>自定义指令</title>
<meta name="description" content="">
<meta name="keywords" content="">
</head>
<body>
<p v-tack class='p'>
I will now be tacked noto the page
<input v-focus type='text'>
<input v-border type='text'>
</p>
</body>
<script type="text/javascript" src='js/vue.min.js'></script>
<script type="text/javascript">
// 自定义全局指令
Vue.directive('border',{
bind(el){
el.style.border='1px red solid'
}
})
new Vue({
el:'.p',
//自定义局部指令
directives:{
tack:{
inserted(el){
el.style.color='red'
}
},
focus: {
// 指令的定义
inserted: function (el) {
el.focus()
}
}
}
})
</script>
</html>