|
@@ -2,7 +2,8 @@
|
|
|
<div class="count">
|
|
|
<h1>计数</h1>
|
|
|
|
|
|
- <h3>求和为:{{countStore.sum}}</h3>
|
|
|
+ <h3>求和为:{{sum}},变大{{ bigSum }}</h3>
|
|
|
+ <h3>我在:{{address}},转大写{{ upCaseAddress }}</h3>
|
|
|
<select v-model.number="num">
|
|
|
<option value="1">1</option>
|
|
|
<option value="2">2</option>
|
|
@@ -20,19 +21,30 @@
|
|
|
import {ref,reactive} from 'vue';
|
|
|
// 1.引用
|
|
|
import {useCountStore} from '@/store/count.ts';
|
|
|
+import {storeToRefs} from 'pinia';
|
|
|
+
|
|
|
+// 2.声明
|
|
|
+const countStore = useCountStore();
|
|
|
+let {sum,address,upCaseAddress,bigSum} = storeToRefs(countStore)
|
|
|
+console.log(sum,'成功');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-// 2.声明
|
|
|
-const countStore = useCountStore();
|
|
|
// console.log(countStore)
|
|
|
// console.log(countStore.$state.sum)
|
|
|
|
|
|
|
|
|
let num = ref(1);
|
|
|
function addNum() {
|
|
|
- countStore.sum += num.value;
|
|
|
+ // 1.修改方法
|
|
|
+ // countStore.sum += num.value;
|
|
|
+ // 2.修改方法
|
|
|
+ // countStore.$patch({
|
|
|
+ // sum:countStore.sum + num.value,
|
|
|
+ // })
|
|
|
+ // 3.修改方式
|
|
|
+ countStore.changeNum(num.value);
|
|
|
}
|
|
|
function reduceNum() {
|
|
|
countStore.sum -= num.value;
|