gpt4 book ai didi

elm - 如何在Elm的同一页面中多次加载带有标志的组件?

转载 作者:行者123 更新时间:2023-12-02 03:52:33 24 4
gpt4 key购买 nike

有没有办法使用 Elm 为页面构建组件,并在同一个 Elm 文件中编译两个组件,并使用相同的代码加载两次相同的组件?

你知道我该怎么做吗?

最佳答案

elm-make 允许您选择要一起编译的多个文件。

elm-make Header.elm Footer.elm Button.elm --output=app.js

标题.elm

port module Header exposing (..)

import Html


main =
Html.div [] [ Html.text "Header" ]

Footer.elm

port module Footer exposing (..)

import Html


main =
Html.div [] [ Html.text "Footer" ]

Button.elm

port module Button exposing (..)

import Html


main =
Html.div [] [ Html.button [] [ Html.text "Button" ] ]

index.html

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Elm Demo</title>
</head>

<body>
<div id="header"></div>
<div id="button"></div>
<div id="button2"></div>
<div id="footer"></div>
</body>
<script src="app.js"></script>
<script>
let header = Elm.Header.embed(document.getElementById("header"));
let footer = Elm.Footer.embed(document.getElementById("footer"));
let button = Elm.Button.embed(document.getElementById("button"));
let button2 = Elm.Button.embed(document.getElementById("button2"));
</script>
</html>

关于elm - 如何在Elm的同一页面中多次加载带有标志的组件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44979588/

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