|
@@ -1,12 +1,29 @@
|
|
|
<template>
|
|
|
- <div class="child">
|
|
|
-
|
|
|
- </div>
|
|
|
- </template>
|
|
|
-
|
|
|
- <script setup name="Child32" lang="ts">
|
|
|
- </script>
|
|
|
-
|
|
|
- <style>
|
|
|
-
|
|
|
- </style>
|
|
|
+ <div class="child">
|
|
|
+ <h1>老二</h1>
|
|
|
+ <p v-show="gift">老大给我的玩具是:{{ gift }}</p>
|
|
|
+ <button @click="emitter.emit('thing',someThing)">告诉老大一个事</button>
|
|
|
+ </div>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script setup name="Child32" lang="ts">
|
|
|
+import emitter from '@/utils/emitter.ts';
|
|
|
+import {ref, onUnmounted} from 'vue';
|
|
|
+let gift = ref("");
|
|
|
+let someThing = ref("瑶瑶是个老六");
|
|
|
+emitter.on("send-toy",(val)=>{
|
|
|
+ // console.log(val);
|
|
|
+ gift.value = val;
|
|
|
+})
|
|
|
+onUnmounted(()=>{
|
|
|
+ emitter.off("send-toy");
|
|
|
+})
|
|
|
+</script>
|
|
|
+
|
|
|
+<style scoped>
|
|
|
+ .child {
|
|
|
+ width: 400px;
|
|
|
+ height: 300px;
|
|
|
+ background: yellowgreen;
|
|
|
+ }
|
|
|
+</style>
|