我有一个简单的elmish直接从模板反应项目,当我运行它时,它加载公共index.html页面,但没有其他任何东西,并且永久地从webpack加载(我猜) bundle.js。
我选择了寓言模板添加了Fable.Elmish.React(nuget)、react(npm)和react(Npm)包。
App.fs
module App
open Fable.React
open Fable.React.Props
open Elmish
open Elmish.React
open Elmish.ReactNative
type Model = Empty
type Msg = NOP
let init () = Empty, Cmd.ofMsg NOP
let update msg model =
match msg with
NOP -> model, Cmd.ofMsg NOP
let view model dispatch =
div [] [
h1 [] [str "Hello, world!"]
]
Program.mkProgram init update view
|> Program.withReactBatched "container"
|> Program.runIndex.html
<!doctype html>
<html>
<head>
<title>TGG</title>
<meta http-equiv='Content-Type' content='text/html; charset=utf-8'>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script defer src="bundle.js"></script>
</head>
<body>
<div class="container">
</body>
</html>发布于 2022-06-09 13:37:16
最后我自己找到了答案
问题出在init函数上
let init () = Empty, Cmd.ofMsg NOP有两个问题,第一个问题是Empty引用的是一个HTML元素,而不是我用来设置所有东西的模拟模型,另一个较小的问题是我应该使用Cmd.ofMsg NOP来代替Cmd.none。
https://stackoverflow.com/questions/72520238
复制相似问题