我正在尝试按照本教程使用 Fable 进行 POST 请求:https ://fable.io/fable-powerpack/posts/fetch.html
我收到此编译错误:
error FSHARP: The value or constructor 'toJson' is not defined. Maybe you want one of the following:
JSON (code 39)
@ ./UI/UI.fsproj 1:0-24 1:0-24
这是我的代码:
let submitForm =
let txtName = getInputElementById("txtName")
let postData = { Name = txtName.value }
let requestProps =
[ RequestProperties.Method HttpMethod.POST
; requestHeaders [ContentType "application/json"]
; RequestProperties.Body (unbox (toJson postData))
]
//Encode.Auto.toString(1, postData)
//toJson
//Fable.Core.JS.JSON.stringify
promise {
let! response = fetch "http://localhost:5000/employee/create" requestProps
let responseText = response.text()
Browser.console.log responseText
} |> ignore
我还在 Fable/.fable/Thoth.Json.2.0.0/Encode.fs 中得到这些编译错误:
The value, constructor, namespace or type 'Array' is not defined. (code 39)
The value, constructor, namespace or type 'JSON' is not defined.
我猜这是因为 Fable 引用的是 Thoth 2.0.0,而不是最新版本。我该如何解决这个错误?
https://github.com/jaydpather/FunctionalCrudForms/blob/master/Fable/UI/UI.fs