Elm 0.19中,Elm.MODULENAME.embed不是一个函数。

20

我正在尝试创建一个简单的Elm项目,它只是将“hello world!”字符串插入到div中。

这是我的代码:

index.html:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8"/>
    <title>ELM Course</title>
  </head>
  <body>
    <div id="hello-world"></div>

    <script src="hello.js"></script>

    <script>
      const myDiv = document.getElementById("hello-world");
      const app = Elm.Hello.embed(myDiv);
    </script>
  </body>
</html>

src/Hello.elm

module Hello exposing (..)

import Html exposing (text)


main =
    text "Hello world!"

我使用以下命令编译JavaScript:

elm make src/Hello.elm --output=hello.js

当我尝试使用浏览器打开index.html时,出现了以下错误:

TypeError: Elm.Hello.embed is not a function
1个回答

43

embed函数已被删除,建议使用init函数。将const app行的JavaScript更改为:

const app = Elm.Hello.init({ node: myDiv });

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接