forked from jigneshbhimani/VueJs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path19beforeDestroy&destroy.txt
62 lines (56 loc) · 1.44 KB
/
19beforeDestroy&destroy.txt
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
beforeDestroy and destroy life cycle hooks in Vue Js
- Make toggle feature with button
- define beforeDestroy and destroy method and use them
1) Make a component
- src/components/Home.vue:
<template>
<div>
<h1>{{name}}</h1>
</div>
</template>
<script>
export default {
name: 'Home',
data(){
return{
name: "Home Component"
}
},
beforeDestroy(){
alert("before");
console.warn("beforeDestroy")
},
destroy(){
alert("destroy");
console.warn("destroyed")
}
}
</script>
- src/App.vue
<template>
<div id="app">
<div v-if="display">
<Home />
</div>
<button v-on:click="toggle">Toggle</button>
</div>
</template>
<script>
import Home from './components/Home.vue'
export default {
name: 'App',
components:{
Home
},
data(){
return{
display:true
}
},
methods:{
toggle(){
this.display=!this.display
}
}
}
</script>