|
@@ -1,12 +1,42 @@
|
|
<template>
|
|
<template>
|
|
<div>
|
|
<div>
|
|
- 父级
|
|
|
|
|
|
+ <h1>$refs-$parent</h1>
|
|
|
|
+ <p>孩子给了我{{ num }}书</p>
|
|
|
|
+ <button @click="changeChild1">改变老大的书</button>
|
|
|
|
+ <button @click="changeChild2">改变老二的花</button>
|
|
|
|
+ <button @click="saveMoney($refs)">保管压岁钱</button>
|
|
|
|
+ <hr />
|
|
|
|
+ <hr />
|
|
|
|
+ <Child1 ref="c1"></Child1>
|
|
|
|
+ <hr />
|
|
|
|
+ <hr />
|
|
|
|
+ <hr />
|
|
|
|
+ <Child2 ref="c2"></Child2>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
</template>
|
|
|
|
|
|
<script lang="ts" setup>
|
|
<script lang="ts" setup>
|
|
-import {ref,reactive} from "vue"
|
|
|
|
-
|
|
|
|
|
|
+import { ref, reactive } from "vue";
|
|
|
|
+import Child1 from "./Child1.vue";
|
|
|
|
+import Child2 from "./Child2.vue";
|
|
|
|
+let c1 = ref();
|
|
|
|
+let c2 = ref();
|
|
|
|
+let num = ref(0);
|
|
|
|
+function changeChild1() {
|
|
|
|
+ console.log(c1.value);
|
|
|
|
+ c1.value.book -= 1;
|
|
|
|
+}
|
|
|
|
+function changeChild2() {
|
|
|
|
+ console.log(c2.value);
|
|
|
|
+ c2.value.flower -= 1;
|
|
|
|
+}
|
|
|
|
+function saveMoney(val: { [propName: string]: any }) {
|
|
|
|
+ console.log(val);
|
|
|
|
+ for (let key in val) {
|
|
|
|
+ val[key].money -= 1000;
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+defineExpose({ num });
|
|
</script>
|
|
</script>
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
<style lang="scss" scoped>
|