|
@@ -1,15 +1,26 @@
|
|
|
<template>
|
|
<template>
|
|
|
<div>
|
|
<div>
|
|
|
<h1>Counter</h1>
|
|
<h1>Counter</h1>
|
|
|
- <h2>当前值为:{{ useCount.sum }}</h2>
|
|
|
|
|
|
|
+ <h2>当前值为:{{ sum }}</h2>
|
|
|
|
|
+ <button @click="changeMain">修改</button>
|
|
|
</div>
|
|
</div>
|
|
|
</template>
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts" setup>
|
|
<script lang="ts" setup>
|
|
|
import { ref, reactive } from "vue";
|
|
import { ref, reactive } from "vue";
|
|
|
import { useCountStore } from "../store/count";
|
|
import { useCountStore } from "../store/count";
|
|
|
|
|
+import { storeToRefs } from "pinia";
|
|
|
// console.log(useCountStore());
|
|
// console.log(useCountStore());
|
|
|
const useCount = useCountStore();
|
|
const useCount = useCountStore();
|
|
|
|
|
+const { sum } = storeToRefs(useCount);
|
|
|
|
|
+function changeMain() {
|
|
|
|
|
+ // useCount.sum = 999;
|
|
|
|
|
+ console.log(useCount);
|
|
|
|
|
+ // useCount.$patch({
|
|
|
|
|
+ // sum: 111,
|
|
|
|
|
+ // });
|
|
|
|
|
+ useCount.addSum(10);
|
|
|
|
|
+}
|
|
|
</script>
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
<style lang="scss" scoped>
|