多页面应用程序
具有多个页面的单个应用程序模块
在构建没有太多逻辑的应用程序时,即使有多个页面,也只需将其全部保留在一个模块中即可。您只需为每个页面定义额外的路由,就像本例中使用`StatisticAnalysis` 模块定义的here :
module App
using GenieFramework
using Statistics
@genietools
# Implement reactive code
@app begin
@in N = 0
@out m = 0.0
@out name = "John"
@onchange N begin
m = mean(rand(N))
end
end
# Define the UI for each page
index() = [h1("Welcome {{name}}!"), a(href="/form")]
function formui()
cell([
textfield("How many numbers?", :N),
p("The average of {{N}} random numbers is {{m}}"),
])
end
# Define the routes
@route("/", index) # use route instead of @page to avoid injecting unnecessary javascript
@page("/form", formui)
end
或者,您也可以将用户界面代码放在一个单独的文件中,并将其作为
@page("/", "ui.jl")
cell([
textfield("How many numbers?", :N),
p("The average of {{N}} random numbers is {{m}}"),
])
多个应用程序模块
如果每个页面都执行不同的功能,例如一个仪表板页面和另一个带有配置面板的页面,则可以在不同的逻辑模块中实现它们。然后,只需将每个模块包含在主`app.jl` 中即可,如本示例所示:
module App
using GenieFramework
include("Index.jl")
include("Form.jl")
end
module Index
using GenieFramework
@app begin
@out name = "John"
end
function ui()
h1("Welcome {{name}}!")
end
@page("/", ui)
end
module Form
using GenieFramework
using Statistics
@app begin
@in N = 0
@out m = 0.0
@onchange N begin
m = mean(rand(N))
end
end
function ui()
cell([
textfield("How many numbers?", :N),
p("The average of {{N}} random numbers is {{m}}"),
])
end
@page("/form", ui)
end