-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
05自定义指令.html
76 lines (71 loc) · 1.75 KB
/
05自定义指令.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src="vue.js"></script>
</head>
<body>
<div id="app">
<my-comp v-if="msg" :msg="msg"></my-comp>
<button @click="update">更新</button>
<button @click="uninstall">卸载</button>
<button @click="install">安装</button>
</div>
<script type="text/javascript">
Vue.component('button-counter', {
data: function () {
return {
count: 0
}
},
mounted: ()=> { //挂载元素,获取到DOM节点
},
template: '<button v-hello="123">You clicked me times.</button>'
})
Vue.directive('hello', {
bind: function (el){
console.log('bind:');
},
inserted: function (el){
console.log('inserted:');
},
update: function (el){
console.log('update:');
},
componentUpdated: function (el){
console.log('componentUpdated:');
},
unbind: function (el){
console.log('unbind:');
}
});
var myComp = {
template: '<button-counter >{{msg}}</button-counter>',
props: {
msg: String
}
}
new Vue({
el: '#app',
data: {
msg: 'Hello'
},
components: {
myComp: myComp
},
methods: {
update: function (){
this.msg = 'Hi';
},
uninstall: function (){
this.msg = '';
},
install: function (){
this.msg = 'Hello';
}
}
})
</script>
</body>
</html>