gpt4 book ai didi

elm - 为什么我不能在Elm 0.19中使用 `onWithOptions`

转载 作者:行者123 更新时间:2023-12-04 13:15:33 25 4
gpt4 key购买 nike

我正在尝试将Elm应用程序从0.18升级到0.19。

我被这个错误困住了-

Detected errors in 1 module.                                         
-- BAD IMPORT ---------------------------------------- src/Views/Interaction.elm

The `Html.Events` module does not expose `onWithOptions`:

13| import Html.Events exposing (onWithOptions)
^^^^^^^^^^^^^
These names seem close though:

onMouseEnter
onMouseLeave
onMouseOut
onMouseOver

documentation显示 onWithOptions应该可用。

我的代码是
module Views.Interaction exposing (onClickNoBubble)

{-| Helper functions for page interactions.


# Helpers

@docs onClickNoBubble

-}

import Html
import Html.Events exposing (onWithOptions)
import Json.Decode as Decode


{-| Replicates the onClick function but prevents bubbling
-}
onClickNoBubble : msg -> Html.Attribute msg
onClickNoBubble message =
onWithOptions "click" { stopPropagation = True, preventDefault = True } (Decode.succeed message)

我该如何前进?

最佳答案

Elm 0.19不使用elm-lang/html。您正在阅读错误的文档。它已由 elm/html 取代,后者具有 custom 函数,该函数具有相同的目的:

onClickNoBubble : msg -> Html.Attribute msg
onClickNoBubble message =
Html.Events.custom "click" (Decode.succeed { message = message, stopPropagation = True, preventDefault = True })

关于elm - 为什么我不能在Elm 0.19中使用 `onWithOptions`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52541501/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com