|
@@ -1,20 +1,43 @@
|
|
|
<template>
|
|
<template>
|
|
|
<div>
|
|
<div>
|
|
|
<h1>计数器</h1>
|
|
<h1>计数器</h1>
|
|
|
- <h3>初始值:{{ count }}</h3>
|
|
|
|
|
|
|
+ <h3>初始值:{{ count }}--变大{{ bigCount }}</h3>
|
|
|
|
|
+ <h3>{{ hi }}--变大写{{ bigWord }}</h3>
|
|
|
|
|
+ <h3>
|
|
|
|
|
+ <input type="text">
|
|
|
|
|
+ <br>
|
|
|
|
|
+ <br>
|
|
|
|
|
+ <select>
|
|
|
|
|
+ <option value="10">10</option>
|
|
|
|
|
+ <option value="15">15</option>
|
|
|
|
|
+ <option value="20">20</option>
|
|
|
|
|
+ </select>
|
|
|
|
|
+ </h3>
|
|
|
|
|
+ <button>添加数值</button>
|
|
|
|
|
+ <button @click="handleAdd1">同步count+1</button>
|
|
|
|
|
+ <button @click="handleAdd2">异步count+2</button>
|
|
|
</div>
|
|
</div>
|
|
|
</template>
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts" setup>
|
|
<script lang="ts" setup>
|
|
|
import {ref,computed} from "vue"
|
|
import {ref,computed} from "vue"
|
|
|
|
|
+import { storeToRefs } from "pinia";
|
|
|
import { useCountStore } from "@/store/count";
|
|
import { useCountStore } from "@/store/count";
|
|
|
const counter = useCountStore();
|
|
const counter = useCountStore();
|
|
|
console.log(counter);
|
|
console.log(counter);
|
|
|
-let {count} = counter;
|
|
|
|
|
|
|
+let {count,bigCount,hi,bigWord} = storeToRefs(counter);
|
|
|
// let count = ref(5);
|
|
// let count = ref(5);
|
|
|
// let bigCount = computed(()=>{
|
|
// let bigCount = computed(()=>{
|
|
|
// return count.value * 3;
|
|
// return count.value * 3;
|
|
|
// })
|
|
// })
|
|
|
|
|
+function handleAdd1() {
|
|
|
|
|
+ console.log("同步count+1");
|
|
|
|
|
+ counter.addCount();
|
|
|
|
|
+}
|
|
|
|
|
+function handleAdd2() {
|
|
|
|
|
+ console.log("异步count+1");
|
|
|
|
|
+ counter.asyncAddCount();
|
|
|
|
|
+}
|
|
|
</script>
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
<style lang="scss" scoped>
|