1选项式
//选项式写法
import {
defineStore
} from "pinia";
//第一个小仓库
//1 下面是一个对象 不需要引入ref;state;actions;getters
let usetoolstore = defineStore('todo', {
state: () => {
return {
todoArr: [{
id: 1,
title: "todo1"
}, {
id: 2,
title: "todo2"
}]
}
},
actions: {
updataFun1() {
this.todoArr.push({
id: 11,
title: 'todo3'
})
}
},
getters: {
}
})
export default usetoolstore
2组合式写法
//组合式写法
import {
defineStore
} from "pinia";
import {
ref,
computed
} from "vue";
//第一个小仓库
let usetoolstore = defineStore('todo', () => {
let todoArr = ref([{
id: 1,
title: "todo1"
}, {
id: 2,
title: "todo2"
}])
let arr = ref([1, 2, 3, 4, 5]) //1定义响应式数据
// 2 没有getter 使用computed
const t