This commit is contained in:
2026-01-14 14:17:38 +08:00
commit f1e2ff6563
126 changed files with 13636 additions and 0 deletions

View File

@@ -0,0 +1,53 @@
# Wails 绑定规范
## 1. 概述
Wails 通过 context 绑定 Go 方法供前端调用,无需 HTTP API。
## 2. Go 后端绑定
### 2.1 结构体定义
```go
type App struct {
ctx context.Context
}
func NewApp() *App {
return &App{}
}
```
### 2.2 方法绑定
- 导出方法(首字母大写)自动绑定
- 方法参数不超过3个超过时使用结构体
- 返回错误统一使用 `error` 类型
### 2.3 命名规范
- 查询:`GetXxx()``ListXxx()`
- 新增:`CreateXxx()``SaveXxx()`
- 更新:`UpdateXxx()`
- 删除:`DeleteXxx()`
## 3. 前端调用
### 3.1 调用方式
```typescript
// 导入绑定的方法
import { GetXxx, SaveXxx } from '@/wailsjs/go/main/App'
// 调用
const data = await GetXxx()
```
### 3.2 错误处理
- 统一使用 try-catch 处理
- 错误信息展示给用户
## 4. 参数规范
- 简单参数直接传递
- 复杂参数使用结构体/对象
- 字段命名使用小驼峰
---
> 文档维护者JueChen
> 创建时间2026-01-07