|
|
@@ -1,12 +1,24 @@
|
|
|
<template>
|
|
|
<div>
|
|
|
<h1>provide-inject</h1>
|
|
|
+ <h2>我有{{ num }}本书</h2>
|
|
|
+ <button @click="changeBook">给孙子一半的书</button>
|
|
|
+ <hr />
|
|
|
+ <hr />
|
|
|
+ <hr />
|
|
|
+ <Child></Child>
|
|
|
</div>
|
|
|
</template>
|
|
|
|
|
|
<script setup>
|
|
|
-import { ref, reactive} from 'vue'
|
|
|
+import { ref, provide } from "vue";
|
|
|
+import Child from "./Child.vue";
|
|
|
+let num = ref(10);
|
|
|
+let sum = ref(0);
|
|
|
+function changeBook() {
|
|
|
+ sum.value = num.value / 2;
|
|
|
+}
|
|
|
+provide("aaa", { sum });
|
|
|
</script>
|
|
|
<style lang='scss' scoped>
|
|
|
-
|
|
|
</style>
|