+
+ count: {{ counter.count }}
+
+
+
+
+
+
+~~~
+#### 4.变更
+用 store.count++ 直接改变 store,还可以调用 $patch 方法
+#### 5.替换
+不能完全替换掉 store 的 state,因为那样会破坏其响应性,还是使用patch
+
+### 四、Getter
+Getter 完全等同于 store 的 state 的计算属性
+~~~js
+export const useCountStore = defineStore('count',{
+ state:()=>{
+ return {count:1}
+ },
+ actions:{
+ onClick(){
+ this.count++
+ }
+ },
+ getters: {
+ doubleCount: (state) => state.count * 2,
+ },
+})
+~~~
+- 大多数时候,getter 仅依赖 state,不过,有时它们也可能会使用其他 getter,通过 this,你可以访问到其他任何 getter
+- getter 只是幕后的计算属性,所以不可以向它们传递任何参数。不过,你可以从 getter 返回一个函数,该函数可以接受任意参数
+~~~js
+export const useUsersStore = defineStore('users', {
+ getters: {
+ getUserById: (state) => {
+ // 可以返回函数,这个返回的函数可以接受容易参数
+ return (userId) => state.users.find((user) => user.id === userId)
+ },
+ },
+})
+ // 调用
+
+~~~
+
+### 五、Action
+Action 相当于组件中的方法,也可通过 this 访问整个 store 实例,而且是可以异步的
\ No newline at end of file
diff --git "a/\350\277\236\345\242\236\351\222\261/20240516_CURD.md" "b/\350\277\236\345\242\236\351\222\261/20240516_CURD.md"
new file mode 100644
index 0000000..fb4214b
--- /dev/null
+++ "b/\350\277\236\345\242\236\351\222\261/20240516_CURD.md"
@@ -0,0 +1,291 @@
+````
+import koa from "koa";
+import cors from "koa2-cors";
+import bodyparser from "koa-bodyparser";
+import Router from "koa-router";
+import { DataTypes, Op, Sequelize, where } from "sequelize";
+const app = new koa();
+const router = new Router()
+const sequelize =new Sequelize("blogs","sa","123456",{
+ host:"127.0.0.1",
+ dialect:"mssql"
+})
+const blog = sequelize.define("blog",{
+ id:{
+ type:DataTypes.INTEGER,
+ primaryKey:true,
+ autoIncrement:true
+ },
+ title:{
+ type:DataTypes.STRING
+ },
+ author:{
+ type:DataTypes.STRING
+ },
+ flag:{
+ type:DataTypes.STRING
+ }
+})
+await blog.sync();
+await blog.bulkCreate([
+ {
+ title:"标题",
+ author:"作者",
+ flag:"标签"
+ },
+ {
+ title:"标题11",
+ author:"作者22",
+ flag:"标签33"
+ }
+])
+// 渲染表格页面
+router.get("/blog",async ctx=>{
+ const data = await blog.findAll();
+ ctx.body={
+ code:1000,
+ data:data
+ }
+})
+// 渲染编辑
+router.get("/edit/:id?",async ctx=>{
+ const id = ctx.params.id
+ const data = await blog.findOne(
+ {
+ where:{
+ id:id
+ }
+ }
+ )
+ ctx.body = {
+ code:1000,
+ data:data
+ }
+})
+// 新增功能
+router.post("/blog",async ctx=>{
+ const {title,author,flag} = ctx.request.body;
+ const data= await blog.create(
+ {
+ title:title,
+ author:author,
+ flag:flag
+ }
+ )
+ ctx.body={
+ code:1000,
+ msg:"新增成功",
+ data:data
+ }
+})
+// 删除功能
+router.delete("/blog/:id?",async ctx=>{
+ const id = ctx.params.id;
+ await blog.destroy(
+ {
+ where:{
+ id:id
+ }
+ }
+ )
+ const data =await blog.findAll();
+ ctx.body={
+ code:1000,
+ data:data,
+ msg:"删除成功"
+ }
+})
+// 编辑功能
+router.put("/blog/:id?",async ctx=>{
+ const id = ctx.params.id
+ const {title,author,flag} = ctx.request.body;
+ await blog.update(
+ {
+ title:title,
+ author:author,
+ flag:flag
+ },
+ {
+ where:{
+ id:id
+ }
+ }
+ )
+ ctx.body={
+ code:1000,
+ msg:"修改成功"
+ }
+})
+// 查询功能
+router.get("/blog/:txt?",async ctx=>{
+ const txt = ctx.params.txt;
+ const data = await blog.findAll(
+ {
+ where:{
+ [Op.or]:[
+ {
+ id:{[Op.like]:`%${txt}%`}
+ },
+ {
+ title:{[Op.like]:`%${txt}%`}
+ },
+ {
+ author:{[Op.like]:`%${txt}%`}
+ },
+ {
+ flag:{[Op.like]:`%${txt}%`}
+ }
+ ]
+ }
+ }
+ )
+ ctx.body={
+ code:1000,
+ data:data
+ }
+})
+app.use(cors());
+app.use(bodyparser());
+app.use(router.routes());
+app.listen(3000,()=>{
+ console.log("http://127.0.0.1:3000");
+})
+````
+
+```
+
+
+