Error

解释失败原因并提供重试操作。

实时预览

正在加载预览…

参数配置

全部字段 9

ErrorOptions

Styles · 0

Go 代码

Go
// Inside a view; c is *ui.Context, t is nui.Theme.
// Keep s (example state) outside the view. See the complete example.
nui.ErrorView(c.Key("error"), t, nui.ErrorOptions{Status: "404", Title: "Project not found", Description: "This example does not make network requests.", OnRetry: func() { s.Retries++ }})
ui.Textf(c, "Retry attempts: %d", s.Retries)

使用说明

点击重试观察计数变化,示例不发起网络请求。ErrorView 展示状态、说明与重试入口;应用在 OnRetry 中启动实际恢复操作。

API 参考

ErrorView

源码
func ErrorView(c *ui.Context, t Theme, o ErrorOptions) ui.Element

ErrorOptions

源码
type ErrorOptions struct {
	Status, Title, Description, RetryLabel string
	Icon                                   *ui.SVG
	OnRetry                                func()
	Actions                                func(*ui.Context, Theme)
	Decoration
}
字段类型说明
Statusstring

Go 零值: ""

状态文字或状态码。

Titlestring

Go 零值: ""

标题文字。

Descriptionstring

Go 零值: ""

补充说明文字。

RetryLabelstring

Go 零值: ""

重试操作的文字。

Icon*ui.SVG

Go 零值: nil

组件使用的 SVG 图标。

OnRetryfunc()

Go 零值: nil

请求重试时通知应用的回调。

Actionsfunc(*ui.Context, Theme)

Go 零值: nil

附加操作或操作区域构建函数。

UIStyles

Go 零值: zero value

以部件名称为键覆盖外观和间距。

Stylefunc(Slot, ui.Element)

Go 零值: nil

同步配置当前构建的部件;不要保留 Element。