You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

47 lines
960 B

import { defineStore } from "pinia";
import { ref } from 'vue'
// 选项式api的写法
// export default defineStore('counter',{
// // 定义数据
// state: () => {
// return {
// count: 1,
// title: '标题',
// }
// },
// // 数据操作
// actions: {
// plus() {
// this.count++;
// },
// sub() {
// this.count--;
// },
// asyncPlus() {
// setTimeout(() => {
// this.count++;
// }, 1000);
// }
// }
// })
// 组合式api写法
export default defineStore('counter', () => {
const count = ref(0);
const plus = () => {
count.value ++;
};
const sub = () => {
count.value --;
};
const asyncPlus = () => {
setTimeout(() => {
count.value++;
}, 1000);
};
return {
count,plus,sub,asyncPlus,
}
});