1
+ const chalk = require ( 'chalk' )
2
+ const custom = require ( '../customcolors' )
3
+ const colorComment = custom . colorComment
4
+ const colorPrimitive = custom . colorPrimitive
5
+ const colorError = custom . colorError
6
+ const colorArgs = custom . colorArgs
7
+
8
+ const cat = 'Options/Lifecycle Hooks'
9
+
10
+ const BEFORE_CREATE = {
11
+ category : cat ,
12
+ name : 'beforeCreate' ,
13
+ type : 'Function' ,
14
+ details : `Called synchronously after the instance has just been initialized,
15
+ before data observation and event/watcher setup.`
16
+ }
17
+
18
+ const CREATED = {
19
+ category : cat ,
20
+ name : 'created' ,
21
+ type : 'Function' ,
22
+ details : `Called synchronously after the instance is created.
23
+ At this stage, the instance has finished processing the options
24
+ which means the following have been set up: data observation, computed
25
+ properties, methods, watch/event callbacks. However, the mounting phase
26
+ has not been started, and the ${ colorArgs ( '$el' ) } property will not be available yet.`
27
+ }
28
+
29
+ const BEFORE_MOUNT = {
30
+ category : cat ,
31
+ name : 'beforeMount' ,
32
+ type : 'Function' ,
33
+ details : `Called right before the mounting begins: the ${ colorArgs ( 'render' ) } function is
34
+ about to be called for the first time.
35
+ ${ chalk . bold ( 'This hook is not called during server-side rendering' ) } .
36
+ `
37
+ }
38
+
39
+ const MOUNTED = {
40
+ category : cat ,
41
+ name : 'mounted' ,
42
+ type : 'Function' ,
43
+ details : `Called after the instance has just been mounted where ${ colorArgs ( 'el' ) } is replaced by the newly created ${ colorArgs ( 'vm.$el' ) } .
44
+ If the root instance is mounted to an in-document element, ${ colorArgs ( 'vm.$el' ) } will also be in-document
45
+ when ${ colorArgs ( 'mounted' ) } is called. ${ chalk . bold ( 'This hook is not called during server-side rendering' ) } .
46
+
47
+ `
48
+ }
49
+
50
+ const BEFORE_UPDATE = {
51
+ category : cat ,
52
+ name : 'beforeUpdate' ,
53
+ type : 'Function' ,
54
+ details : `Called when the data changes, before the virtual DOM is re-rendered and patched.
55
+ You can perform further state changes in this hook and they will not trigger additional re-renders.
56
+ ${ chalk . bold ( 'This hook is not called during server-side rendering' ) } .
57
+
58
+ `
59
+ }
60
+
61
+ const UPDATED = {
62
+ category : cat ,
63
+ name : 'updated' ,
64
+ type : 'Function' ,
65
+ details : `Called after a data change causes the virtual DOM to be re-rendered and patched.
66
+ The component’s DOM will have been updated when this hook is called,
67
+ so you can perform DOM-dependent operations here. However, in most cases
68
+ you should avoid changing state inside the hook. To react to state changes,
69
+ it’s usually better to use a ${ chalk . green ( 'computed property' ) } or ${ chalk . green ( 'watcher' ) } instead.
70
+ ${ chalk . bold ( 'This hook is not called during server-side rendering' ) } .
71
+ `
72
+ }
73
+
74
+ const ACTIVATED = {
75
+ category : cat ,
76
+ name : 'activated' ,
77
+ type : 'Function' ,
78
+ details : `Called when a kept-alive component is activated.
79
+ ${ chalk . bold ( 'This hook is not called during server-side rendering' ) } .`
80
+ }
81
+
82
+ const DEACTIVATED = {
83
+ category : cat ,
84
+ name : 'deactivated' ,
85
+ type : 'Function' ,
86
+ details : `Called when a kept-alive component is deactivated.
87
+ ${ chalk . bold ( 'This hook is not called during server-side rendering' ) } .`
88
+ }
89
+
90
+ const BEFORE_DESTROY = {
91
+ category : cat ,
92
+ name : 'beforeDestroy' ,
93
+ type : 'Function' ,
94
+ details : `Called right before a Vue instance is destroyed. At this stage the instance is
95
+ still fully functional. ${ chalk . bold ( 'This hook is not called during server-side rendering' ) } .`
96
+ }
97
+
98
+ const DESTROYED = {
99
+ category : cat ,
100
+ name : 'destroyed' ,
101
+ type : 'Function' ,
102
+ details : `Called after a Vue instance has been destroyed. When this hook is called, all directives of the Vue instance
103
+ have been unbound, all event listeners have been removed, and all child Vue instances have also been
104
+ destroyed. ${ chalk . bold ( 'This hook is not called during server-side rendering' ) } .`
105
+ }
106
+
107
+ module . exports = {
108
+ BEFORE_CREATE ,
109
+ CREATED ,
110
+ BEFORE_MOUNT ,
111
+ MOUNTED ,
112
+ BEFORE_UPDATE ,
113
+ UPDATED ,
114
+ ACTIVATED ,
115
+ DEACTIVATED ,
116
+ BEFORE_DESTROY ,
117
+ DESTROYED
118
+ }
0 commit comments