由于@glennsl的提示,这个问题得到了理想的解决。
import Browser
import Html exposing (Html, button, div, text)
import Html.Attributes exposing (disabled)
import Html.Events exposing (onClick)
main =
Browser.sandbox
{ init =
{ count = 0
, added = False
, inactive = False
}
, update = update
, view = view
}
type Msg
= Increment
| AddNode
update msg model =
case msg of
Increment ->
{ model | count = model.count + 1 }
AddNode ->
{ model | inactive = True, added = True }
view model =
let
viewStatic =
button
[ disabled model.inactive
, onClick AddNode
]
[ text "new" ]
viewDynamic =
div []
[ text (String.fromInt model.count) ]
in
div []
[ viewStatic
, if model.added then
div []
[ button [ onClick Increment ] [ text "+" ]
, viewDynamic
]
else
text ""
]