forked from jigneshbhimani/VueJs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path11Props(2).txt
55 lines (49 loc) · 1.54 KB
/
11Props(2).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
Send Props Child to Parent
- Make a child component
- Call a function on button click
- Emit a event from function
- call parent component function with event emmiter
- Update Title
1) Make a Child Component
- src/components/Child.vue:
<template>
<div>
<button v-on:click="updateTitle">Update Parent Title</button> // v-on:click="updateTitle"
</div>
</template>
<script>
export default {
name: 'Child',
methods:{
updateTitle(){ // updateTitle() method define
this.$emit('changeTitle','props updated title'); // $emit ma changeTitle use karyu
}
}
}
</script>
- src/App.vue:
<template>
<div id="app">
<h1>{{title}}</h1>
<Child v-on:changeTitle="updateTitle($event)"/> // v-on:changeTitle="updateTitle($event)"
</div>
</template>
<script>
import Child from './components/Child.vue'
export default {
name: 'App',
components:{
Chilld
},
data(){
return{
title: 'Props Tutorial'
}
},
methods:{
updateTitle(){ // Update Title
this.title = title
}
}
}
</script>