@@ -2926,7 +2926,7 @@
},
"node_modules/mitt": {
"version": "3.0.1",
- "resolved": "https://registry.npmjs.org/mitt/-/mitt-3.0.1.tgz",
+ "resolved": "https://registry.npmmirror.com/mitt/-/mitt-3.0.1.tgz",
"integrity": "sha512-vKivATfr97l2/QBCYAkXYDbrIWPM2IIKEl7YPhjCvKlG3kE2gm+uBo6nEXK3M5/Ffh/FLpKExzOQ3JJoJGFKBw==",
"license": "MIT"
@@ -0,0 +1,22 @@
+import mitt from 'mitt'
+
+const emitter = mitt()
+// listen to an event
+// emitter.on('foo', e => console.log('foo', e))
+// listen to all events
+// emitter.on('*', (type, e) => console.log(type, e))
+// fire an event
+// emitter.emit('foo', { a: 'b' })
+// clearing all events
+// emitter.all.clear()
+// working with handler references:
+// function onFoo() { }
+// emitter.on('foo', onFoo) // listen
+// emitter.off('foo', onFoo) // unlisten
+export default emitter;
@@ -0,0 +1,12 @@
+<template>
+ <div>
+ <h1 class="h-26 text-6xl">子组件1</h1>
+ </div>
+</template>
+<script lang="ts" setup>
+import { ref, reactive } from "vue";
+</script>
+<style lang="scss" scoped>
+</style>
+ <h1 class="h-26 text-6xl">子组件2</h1>
@@ -0,0 +1,23 @@
+ <h1 class="h-26 text-6xl">Refs-Parent</h1>
+ <h3 class="h-16 text-4xl"></h3>
+ <hr class="h-15" />
+ <Child1></Child1>
+ <Child2></Child2>
+import Child1 from "./Child1.vue";
+import Child2 from "./Child2.vue";
@@ -0,0 +1,19 @@
+ <h1 class="h-26 text-6xl">我有{{ flower }}朵花</h1>
+ <button @click="sendFlower">给朋友一些花</button>
+import emitter from "@/utils/emitter.js";
+let flower = ref(10);
+const sendFlower = () => {
+ emitter.emit("xxx", flower.value / 2);
+};
@@ -0,0 +1,21 @@
+ <h1 class="h-26 text-6xl">收到了{{ num }}朵花</h1>
+import { ref, reactive, onUnmounted } from "vue";
+let num = ref<number>(0);
+emitter.on("xxx", (val: number) => {
+ num.value = val;
+});
+onUnmounted(() => {
+ emitter.off("xxx");
+ <h1 class="h-26 text-6xl">Mitt</h1>