You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Fabulous.MAUI中View.map报错:No overloads match for method 'Yield'

解决Fabulous.MAUI中View.map的"No overloads match for method 'Yield'"错误

错误根源在于FirstPage的view函数返回了整个Application结构,而App模块的NavigationPage期望的是单个页面(比如ContentPage)作为子元素,类型不匹配导致触发Yield方法重载错误。

修改方案

1. 调整FirstPage.fs的view函数

去掉外层的Application包裹,直接返回ContentPage:

module firstpage

open Fabulous
open Fabulous.Maui
open Microsoft.Maui.Accessibility
open Microsoft.Maui
open type Fabulous.Maui.View

type Model = { Name: string }

type Msg = | Clicked

let init () = { Name = "Alex"}

let update msg model =
        match msg with
        | Clicked -> { model with Name = "Verca"}

let view model =
        ContentPage(
            VStack (spacing =25.) {
                Label($"Hello, {model.Name}")
                    .semantics(SemanticHeadingLevel.Level1)
                    .font(size = 32.)
                    .centerTextHorizontal()

                Button("Click", Clicked)
            }
        )

2. 保留App.fs现有代码

修改FirstPage后,App模块中View.map的类型会自动匹配,原代码无需额外调整:

let view model =
    NavigationPage () {
        View.map FirstPageMsg (firstpage.view model.FirstpageModel)
    }

关键说明

  • Fabulous的NavigationPage()容器仅接受页面级组件(如ContentPage)作为子元素,FirstPage原代码返回的Application属于应用根结构,无法被NavigationPage嵌套。
  • View.map的作用是将子页面的Msg包装为父页面的Msg,要求子视图必须是符合Fabulous页面规范的组件,调整后的ContentPage正好满足类型要求。

内容的提问来源于stack exchange,提问作者Alex_P

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.12 15:42:06