Skip to content
This repository was archived by the owner on Jun 29, 2021. It is now read-only.

Commit b5771e5

Browse files
author
renl
committed
child.vue emit
1 parent f20c39a commit b5771e5

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

src/App.vue

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,26 @@
55
<p v-for="v in 3" :key="v">{{v}}</p>
66
<h4 ref="h4">{{num}}</h4>
77
<button @click="inc">Clicked {{ count }} times.</button>
8+
<Child @childEvent="childEvent"/>
89
</div>
910
</template>
1011

1112
<script>
1213
import { ref, onBeforeMount, watch, watchEffect, reactive, onMounted } from 'vue'
14+
import Child from './compents/Child.vue'
1315
1416
export default {
15-
setup() {
17+
components: {
18+
Child
19+
},
20+
emits: {
21+
childEvent (val) {
22+
console.log(val)
23+
return true
24+
}
25+
},
26+
setup(props, context) {
27+
console.log(context)
1628
const count = ref(0)
1729
const num = ref(1)
1830
const datas = reactive({
@@ -32,6 +44,11 @@ export default {
3244
}
3345
const h4 = ref(null)
3446
47+
const childEvent = (val) => {
48+
console.log(val)
49+
return true
50+
}
51+
3552
onBeforeMount(() => {
3653
initTem()
3754
initEnd()
@@ -55,6 +72,7 @@ export default {
5572
count,
5673
num,
5774
h4,
75+
childEvent,
5876
inc
5977
}
6078
}

src/compents/Child.vue

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<template>
2+
<div>this is child</div>
3+
</template>
4+
<script>
5+
export default {
6+
setup (props, context) {
7+
context.emit('childEvent', '孩子from child')
8+
return {}
9+
}
10+
}
11+
</script>
12+
<style lang="less" scoped>
13+
</style>

0 commit comments

Comments
 (0)