|
@@ -0,0 +1,47 @@
|
|
|
+<template>
|
|
|
+ <div class="father">
|
|
|
+ <h1>父组件</h1>
|
|
|
+ <h4>我有{{num}}个粽子</h4>
|
|
|
+ <button @click="change1">修改奥特曼数量</button>
|
|
|
+ <br><br>
|
|
|
+ <button @click="change2">修改喜羊羊数量</button>
|
|
|
+ <br><br>
|
|
|
+ <button @click="change3($refs)">修改钱数</button>
|
|
|
+ <Child ref="c1"></Child>
|
|
|
+ <hr>
|
|
|
+ <Child1 ref="c2"></Child1>
|
|
|
+ </div>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script setup lang="ts" name="Father5">
|
|
|
+import Child from './Child.vue';
|
|
|
+import Child1 from './Child1.vue';
|
|
|
+import {ref, defineExpose} from 'vue';
|
|
|
+let num = ref(10);
|
|
|
+let c1 = ref("");
|
|
|
+let c2 = ref("");
|
|
|
+function change1() {
|
|
|
+ console.log(c1.value.toy);
|
|
|
+ c1.value.toy += 1;
|
|
|
+}
|
|
|
+function change2() {
|
|
|
+ c2.value.sheep += 1;
|
|
|
+}
|
|
|
+function change3($refs:{[key:string]:any}) {
|
|
|
+ console.log($refs)
|
|
|
+ // console.log(key,'key')
|
|
|
+ for(let a in $refs) {
|
|
|
+ console.log($refs[a]);
|
|
|
+ $refs[a].money += 100;
|
|
|
+ }
|
|
|
+}
|
|
|
+defineExpose({num});
|
|
|
+</script>
|
|
|
+
|
|
|
+<style scoped>
|
|
|
+ .father {
|
|
|
+ width: 1200px;
|
|
|
+ height: 1200px;
|
|
|
+ background: aqua;
|
|
|
+ }
|
|
|
+</style>
|