我正在尝试以下页面中标题为“添加客户端功能”的示例片段:
https://developers.websharper.com/docs/v4.x/fs/overview
它看起来有点过时并且无法按原样编译,因此基于从该代码被剪断的原始存储库,这就是我现在所拥有的。
namespace TestSuaveWs
open WebSharper
open WebSharper.Sitelets
open WebSharper.UI
open WebSharper.UI.Html
open WebSharper.UI.Client
module Server =
[<Rpc>]
let DoWork (s: string) =
async {
return System.String(List.ofSeq s |> List.rev |> Array.ofList)
}
[<JavaScript>]
module Client =
open WebSharper.JavaScript
open WebSharper.Html.Client
let Main () =
let input = Input [ Attr.Value "" ]
let output = H1 []
Div [
input
Button [ Text "Send" ]
|>! OnClick (fun _ _ ->
async {
let! data = Server.DoWork input.Value
output.Text <- data
}
|> Async.Start
)
HR []
H4 [ Class "text-muted" ] -- Text "The server responded:"
Div [ Class "jumbotron" ] -< [ output ]
]
module TheSite =
open WebSharper.UI.Server
[<Website>]
let MySite =
Application.SinglePage (fun ctx ->
Content.Page(
Body = [
h1 [] [ text "Say Hi to the server" ]
div [] [ client <@ Client.Main() @> ]
]
)
)
open global.Suave
open Suave.Web
open WebSharper.Suave
let webPart = WebSharperAdapter.ToWebPart(MySite, RootDirectory="../..")
然后是主程序。
namespace TestSuaveWs
module Main =
open System
open System.Threading
open Suave
[<EntryPoint>]
let main argv =
let cts = new CancellationTokenSource()
let conf = { defaultConfig with cancellationToken = cts.Token }
let listening, server = startWebServerAsync conf TheSite.webPart
Async.Start(server, cts.Token)
printfn "Make requests now"
Console.ReadKey true |> ignore
cts.Cancel()
0
程序运行,我可以在 localhost:8080 上看到文本“Say Hi to the server”,但该文本下方没有任何内容。页面上带有示例的图片显示了它的外观。应该有一个文本输入字段、一个按钮和一个回复文本。
当我在 Chrome 浏览器中打开开发者工具时,我可以看到有一堆类似的消息,只是 javascript 文件名不同,上面写着“加载资源失败:服务器响应状态为 404 WebSharper.Main.min。 js:1(未找到)"
bin\Debug 文件夹中没有 *.js 文件。我在 VS 2019 中运行,使用 .NET Framework 4.7.1。
我错过了什么?