Ich habe Probleme damit, den besten Stil für meine Elm 19-App zu finden. Folgendes habe ich vergeblich versucht:
module Main exposing (..) import Browser import Html exposing (..) import Html.Attributes exposing (..) import Html.Styled.Attributes exposing (css) import List exposing (..) import Css exposing (..) type alias Model = List Status type alias Status = { status : String } main = Browser.element { init = init , view = view , update = update , subscriptions = subscriptions } -- Note: I removed the init, update, and subscriptions functions from this code snippet as it does not seem like they were relevant to my question. view : Model -> Html Msg view model = main_ [ css [ color (hex "ffffff") , backgroundColor (hex "000000") , Css.height (vh 100) ] ] [ h1 [ css [ margin (px 0) ] ] [ text "The title of my app" ] , input [ value ""] [] ]
Der Compiler wies darauf hin, dass das Problem, auf das ich in main_
gestoßen bin, wie folgt war:
<!-- language: lang-none --> This argument is a list of type: List #(Html.Styled.Attribute msg)# But `main_` needs the 1st argument to be: List #(Attribute msg)#
Dies ist die elm.json
-Datei:
{ "type": "application", "source-directories": [ "src" ], "elm-version": "0.19.1", "dependencies": { "direct": { "elm/browser": "1.0.2", "elm/core": "1.0.5", "elm/html": "1.0.0", "elm/time": "1.0.0", "ianmackenzie/elm-units": "2.9.0", "justinmimbs/date": "4.0.1", "rtfeldman/elm-css": "18.0.0" }, "indirect": { "elm/json": "1.1.3", "elm/parser": "1.1.0", "elm/url": "1.0.0", "elm/virtual-dom": "1.0.3", "robinheghan/murmur3": "1.0.0", "rtfeldman/elm-hex": "1.0.0" } }, "test-dependencies": { "direct": {}, "indirect": {} } }
Ich vermute, dass ich eine ältere Version von elm-css
oder etwas Ähnliches verwende, aber ich habe Probleme zu verstehen, was hier bei mir nicht funktioniert.
为了使用
elm-css
,您需要使用Html.Styled.toUnstyled
从Html.Styled.Html
转换为Html.Html
。这意味着您需要import Html.Styled 暴露 (..)
而不是import Html 暴露 (..)
这意味着
main_
将是Html.Syled.main_
而不是Html.main_
(现在是这样)。然后,您可以在
view
代码的末尾添加|> Html.Styled.toUnstyled
,一切都会正常进行。