Skip to content

Commit b729851

Browse files
committed
Add Passing Props & Listners working example
1 parent 73a8d2f commit b729851

File tree

4 files changed

+129
-54
lines changed

4 files changed

+129
-54
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<template>
2+
<p class="demo">
3+
<passing-props
4+
title="This is from <passing-props />"
5+
childPropA="This is from <passing-props-child />"
6+
@click="handleClickPassingPropsChildComponent"
7+
>
8+
</passing-props>
9+
</p>
10+
</template>
11+
12+
<script>
13+
import PassingProps from './PassingProps';
14+
15+
export default {
16+
components: {
17+
PassingProps,
18+
},
19+
methods: {
20+
handleClickPassingPropsChildComponent() {
21+
console.log('This event comes from `<passing-props-child />`');
22+
alert('This event comes from `<passing-props-child />`');
23+
},
24+
},
25+
};
26+
</script>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<template>
2+
<div>
3+
<h1>{{title}}</h1>
4+
<passing-props-child v-bind="$attrs" v-on="$listeners"></passing-props-child>
5+
</div>
6+
</template>
7+
8+
<script>
9+
import PassingPropsChild from './PassingPropsChild';
10+
11+
export default {
12+
components: {
13+
PassingPropsChild,
14+
},
15+
inheritAttrs: false,
16+
props: {
17+
title: {
18+
type: String,
19+
default: 'Hello, Vue!',
20+
},
21+
},
22+
};
23+
</script>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<template>
2+
<button class="btn btn-primary" @click="$emit('click')">{{childPropA}}</button>
3+
</template>
4+
5+
<script>
6+
export default {
7+
props: {
8+
childPropA: String,
9+
},
10+
};
11+
</script>

0 commit comments

Comments
 (0)