From b4ab28999c606c8793102c6fd9bf23abfc891fc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A7=9A=E6=A2=A6=E7=94=B7?= <2609921471@qq.com> Date: Sun, 19 May 2024 21:04:54 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=A7=9A=E6=A2=A6=E7=94=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...66\346\200\201\347\256\241\347\220\206.md" | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 "\345\247\232\346\242\246\347\224\267/20240513-pinia\347\212\266\346\200\201\347\256\241\347\220\206.md" diff --git "a/\345\247\232\346\242\246\347\224\267/20240513-pinia\347\212\266\346\200\201\347\256\241\347\220\206.md" "b/\345\247\232\346\242\246\347\224\267/20240513-pinia\347\212\266\346\200\201\347\256\241\347\220\206.md" new file mode 100644 index 0000000..cd2e5b0 --- /dev/null +++ "b/\345\247\232\346\242\246\347\224\267/20240513-pinia\347\212\266\346\200\201\347\256\241\347\220\206.md" @@ -0,0 +1,48 @@ +# pinia +Pinia 是 Vue 的专属状态管理库,它允许你跨组件或页面共享状态。如果你熟悉组合式 API 的话,你可能会认为可以通过一行简单的 export const state = reactive({}) 来共享一个全局状态。对于单页应用来说确实可以,但如果应用在服务器端渲染,这可能会使你的应用暴露出一些安全漏洞。 而如果使用 Pinia,即使在小型单页应用中,你也可以获得如下功能: + +Devtools 支持 +追踪 actions、mutations 的时间线 +在组件中展示它们所用到的 Store +让调试更容易的 Time travel +热更新 +不必重载页面即可修改 Store +开发时可保持当前的 State +插件:可通过插件扩展 Pinia 功能 +为 JS 开发者提供适当的 TypeScript 支持以及自动补全功能。 +支持服务端渲染 +下载 +``` +yarn add pinia +``` +使用 +``` +// stores/counter.js +import { defineStore } from 'pinia' + +export const useCounterStore = defineStore('counter', { + state: () => { + return { count: 0 } + }, + // 也可以这样定义 + // state: () => ({ count: 0 }) + actions: { + increment() { + this.count++ + }, + }, +}) + + +``` \ No newline at end of file -- Gitee From eaaaa12c80e65986aa8934f9268ce120e4822b9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A7=9A=E6=A2=A6=E7=94=B7?= <2609921471@qq.com> Date: Sun, 23 Jun 2024 21:21:56 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=A7=9A=E6=A2=A6=E7=94=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../20240617-\350\267\250\345\237\237.md" | 20 +++++++++++++++ ...32\345\256\242\347\273\203\344\271\240.md" | 25 +++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 "\345\247\232\346\242\246\347\224\267/20240617-\350\267\250\345\237\237.md" create mode 100644 "\345\247\232\346\242\246\347\224\267/20240619-\345\215\232\345\256\242\347\273\203\344\271\240.md" diff --git "a/\345\247\232\346\242\246\347\224\267/20240617-\350\267\250\345\237\237.md" "b/\345\247\232\346\242\246\347\224\267/20240617-\350\267\250\345\237\237.md" new file mode 100644 index 0000000..4522130 --- /dev/null +++ "b/\345\247\232\346\242\246\347\224\267/20240617-\350\267\250\345\237\237.md" @@ -0,0 +1,20 @@ +# 在ASP.NET Core应用程序中配置CORS(跨域资源共享)策略 +``` +public void ConfigureServices(IServiceCollection services) +{ + // 添加跨域服务 + services.AddCors(options => { + // "AllowOrigin"是策略的名称,你可以根据需要命名它 + options.AddPolicy("AllowOrigin",builder => { + builder.AllowAnyOrigin() //指定允许来自任何来源的请求,WithOrigins制定对某些域名开放 + .AllowAnyMethod() //指定允许任何HTTP方法 + .AllowAnyHeader(); //指定允许任何请求头 + }); + }); +} +public void Configure(IApplicationBuilder app,IHostEnvironment env) +{ + // 使用 "AllowOrigin" 策略,要在启用路由中间件后使用 + app.UseCors("AllowOrigin"); +} +``` \ No newline at end of file diff --git "a/\345\247\232\346\242\246\347\224\267/20240619-\345\215\232\345\256\242\347\273\203\344\271\240.md" "b/\345\247\232\346\242\246\347\224\267/20240619-\345\215\232\345\256\242\347\273\203\344\271\240.md" new file mode 100644 index 0000000..3a43f61 --- /dev/null +++ "b/\345\247\232\346\242\246\347\224\267/20240619-\345\215\232\345\256\242\347\273\203\344\271\240.md" @@ -0,0 +1,25 @@ +# 博客表考前梳 +### 后端webapi +1. 配置入口文件Program.cs +2. 配置启动类,注册依赖Startup.cs +3. 创建封装表格Domain/Blog.cs +4. 创建表格数据实体类Dto:BlogCreateDto、BlogDto、BlogUpdateDto +5. 在配置文件中编写数据库连接字符串 +``` + "ConnectionStrings": { + "SqlServer": "server=.;database=BlogDemo;uid=sa;pwd=123456;TrustServerCertificate=true;" + } +``` +6. 创建数据库上下文,连接数据库Db/BlogsDbContext +7. 创建通用仓储接口Interfaces/IRepositoryBase.cs +8. 实现接口Services/RepositoryBase.cs +9. 编写控制器 +10. 生成迁移和同步数据库 +``` +// 全局安装dotnet-ef工具 +dotnet tool install --global dotnet-ef +// 生成迁移 +dotnet ef migrations add +// 同步数据库 +dotnet ef batadase update +``` \ No newline at end of file -- Gitee