|
|
@@ -1,15 +1,17 @@
|
|
|
<template>
|
|
|
<div>
|
|
|
- <h1 class="h-26 text-6xl">Refs-Parent</h1>
|
|
|
- <h3 class="h-16 text-4xl"></h3>
|
|
|
+ <h1 class="h-26 text-6xl">$refs-$parent</h1>
|
|
|
+ <h3 class="h-16 text-4xl">我有{{ car }}辆车</h3>
|
|
|
+ <button @click="getMain">获取</button>
|
|
|
+ <button @click="changeMain($refs)">改变</button>
|
|
|
<hr class="h-15" />
|
|
|
<hr class="h-15" />
|
|
|
<hr class="h-15" />
|
|
|
- <Child1></Child1>
|
|
|
+ <Child1 ref="c1"></Child1>
|
|
|
<hr class="h-15" />
|
|
|
<hr class="h-15" />
|
|
|
<hr class="h-15" />
|
|
|
- <Child2></Child2>
|
|
|
+ <Child2 ref="c2"></Child2>
|
|
|
</div>
|
|
|
</template>
|
|
|
|
|
|
@@ -17,6 +19,21 @@
|
|
|
import { ref, reactive } from "vue";
|
|
|
import Child1 from "./Child1.vue";
|
|
|
import Child2 from "./Child2.vue";
|
|
|
+let car = ref(10);
|
|
|
+let c1 = ref();
|
|
|
+let c2 = ref();
|
|
|
+function getMain() {
|
|
|
+ c1.value.money -= 100;
|
|
|
+ c2.value.money -= 100;
|
|
|
+ console.log(c1.value, "c1");
|
|
|
+ console.log(c2.value, "c2");
|
|
|
+}
|
|
|
+const changeMain = (val: { [propsName: string]: any }) => {
|
|
|
+ for (let key in val) {
|
|
|
+ val[key].money += 100;
|
|
|
+ }
|
|
|
+};
|
|
|
+defineExpose({ car });
|
|
|
</script>
|
|
|
|
|
|
<style lang="scss" scoped>
|