javascript - 是否可以将 Javascript UI 元素添加到 100% elm 应用程序中?

标签 javascript interop elm

我有一个运行良好的榆树应用程序。它有一个我们使用标准的 elm UI 功能代码构建的导航栏。有人看到我的应用程序并说您应该使用我们的标准 javascript 工具栏 UI 组件。是否可以将 Javascript UI 组件嵌入到 100% native ELM 应用程序中?

请注意,我们已经在使用端口来调用一些 native JavaScript 函数。我想知道是否可以使用相同的概念来嵌入 UI 组件,但由于 ELM 有它自己的内部渲染,这会有问题吗?

最佳答案

我不清楚您所说的“Javascript UI 组件”是什么意思,因为它可以指代许多不同的东西,例如 react 组件或 Angular 组件。但 Elm 确实支持标准 Web Components通过Custom Elements .

这里有一个不完整的例子,说明它在 Elm 方面的样子,从 Beginning Elm 借用(并做了一些编辑)。 :

googleMap : List (Attribute a) -> List (Html a) -> Html a
googleMap =
    Html.node "google-map"


onGoogleMapDrag : Attribute Msg
onGoogleMapDrag =
    coordinatesDecoder
        |> Json.Decode.map UpdateCenter
        |> on "google-map-drag"


view : Model -> Html Msg
view model =
    googleMap
        [ attribute "latitude" (toString model.center.latitude)
        , attribute "longitude" (toString model.center.longitude)
        , attribute "drag-events" "true"
        , attribute "zoom" "5"
        , onGoogleMapDrag
        ]
        (List.map viewMarker model.markers)

关于javascript - 是否可以将 Javascript UI 元素添加到 100% elm 应用程序中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54892698/

相关文章:

javascript - 使 Highcharts 散布圆形阴影

php - 使用 openssl_encrypt AES-CBC 实现 Python 到 PHP 兼容的 AES 加密

functional-programming - 使用条件查询参数构建 URL

javascript - 为什么我的条形图是倒置的?

javascript - 在 highcharter 中包含导出 csv

c# - F# 命名空间/模块和与 C# 的互操作

vb.net - 我如何使用 vb.net 读取 Excel 工作表的文本框(尝试使用 uipath 调用代码事件自动化流程)

haskell - 代码在 Elm 中编译,但在 Haskell 中不编译

elm - 如何对测试 API 模块内的 Cmd 消息进行模式匹配?

javascript - 如何使用 javascript 循环和数组显示图像幻灯片?