我正在尝试创建一个简单的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>
Run Code Online (Sandbox Code Playgroud)
SRC/Hello.elm
module Hello exposing (..)
import Html exposing (text)
main =
text "Hello world!"
Run Code Online (Sandbox Code Playgroud)
我使用以下命令编译javascript:
elm make src/Hello.elm --output=hello.js
Run Code Online (Sandbox Code Playgroud)
当我尝试使用浏览器打开index.html时出现问题,我收到此错误:
TypeError: Elm.Hello.embed is not a function
Run Code Online (Sandbox Code Playgroud)
Cha*_*ert 34
该embed功能已被删除,以支持init.将const app行上的javascript更改为:
const app = Elm.Hello.init({ node: myDiv });
Run Code Online (Sandbox Code Playgroud)