|
|
@@ -1,12 +1,48 @@
|
|
|
<template>
|
|
|
<div>
|
|
|
<h1>$refs-$parent</h1>
|
|
|
+ <h2>child1给了我{{ bookNum }}本书</h2>
|
|
|
+ <button @click="changeNum1">改变Child1书的数量</button>
|
|
|
+ <button @click="changeNum2">改变Child2花的数量</button>
|
|
|
+ <h1 v-if="c1">Child1给了我{{ c1.new1 }}本书</h1>
|
|
|
+ <button @click="handleMoney($refs)">获取他们的钱</button>
|
|
|
+ <hr>
|
|
|
+ <hr>
|
|
|
+ <hr>
|
|
|
+ <hr>
|
|
|
+ <Child1 ref="c1"></Child1>
|
|
|
+ <hr>
|
|
|
+ <hr>
|
|
|
+ <hr>
|
|
|
+ <hr>
|
|
|
+ <Child2 ref="c2"></Child2>
|
|
|
</div>
|
|
|
</template>
|
|
|
|
|
|
<script lang="ts" setup>
|
|
|
import {ref,reactive} from "vue"
|
|
|
-
|
|
|
+import Child1 from "./Child1.vue";
|
|
|
+import Child2 from "./Child2.vue";
|
|
|
+let c1 = ref();
|
|
|
+let c2 = ref();
|
|
|
+let bookNum = ref(0);
|
|
|
+// console.log(c1.value,c2.value);
|
|
|
+const changeNum1 = () => {
|
|
|
+ console.log(c1.value);
|
|
|
+ c1.value.book--;
|
|
|
+}
|
|
|
+const changeNum2 = () => {
|
|
|
+ console.log(c2.value);
|
|
|
+ c2.value.flower--;
|
|
|
+}
|
|
|
+function handleMoney(val:any) {
|
|
|
+ console.log(val);
|
|
|
+ for(let key in val) {
|
|
|
+ console.log(key)
|
|
|
+ val[key].money -= 200;
|
|
|
+ }
|
|
|
+}
|
|
|
+defineExpose({bookNum})
|
|
|
</script>
|
|
|
|
|
|
<style lang="scss" scoped>
|