zheng 11 hours ago
parent
commit
ff2c1237fa
2 changed files with 14 additions and 1 deletions
  1. 11 0
      20.vue3/project5/src/App.vue
  2. 3 1
      20.vue3/project5/src/store/count.ts

+ 11 - 0
20.vue3/project5/src/App.vue

@@ -2,6 +2,13 @@
   <div>
     <h1>Pinia</h1>
     <h2>当前值是:{{ countStore.num }}--双倍:{{ countStore.doubleNum }}</h2>
+    <select v-model="sum">
+      <option value="1">1</option>
+      <option value="2">2</option>
+      <option value="3">3</option>
+      <option value="4">4</option>
+    </select>
+    <button @click="addMain">增加</button>
   </div>
 </template>
 
@@ -11,7 +18,11 @@ import { useCountStore } from "./store/count";
 const countStore = useCountStore();
 console.log(countStore);
 let num = ref(0);
+let sum = ref(1);
 num.value = countStore.num;
+function addMain() {
+  countStore.handeleAdd(Number(sum.value));
+}
 </script>
 
 <style lang="scss" scoped>

+ 3 - 1
20.vue3/project5/src/store/count.ts

@@ -17,6 +17,8 @@ export const useCountStore = defineStore('count1', {
     },
     // methods
     actions: {
-
+        handeleAdd(val: number) {
+            this.num += val;
+        }
     }
 })