如何使图像呈现榆树?

问题描述 投票:0回答:1

如何在Elm视图中渲染图像?

这是我的代码:

view : Model -> Html Msg
view model =
    div []
        [ img [src "https://cameras.liveviewtech.com/img/LVLogo_small.png"] []
        , input [ onInput ChangeUserInput ] []
        , button [ onClick ClearText ] [ text "Clear" ]
        , button [ onClick SaveText ] [ text "Save" ]
        , div [] (List.map rowItem model.textToDisplay)
        ]

我收到错误代码

我找不到“ img”变量:我找不到“ src”变量:

如何显示图像?我在做什么错?

这是我的进口商品:

module Main exposing (main)    
import Browser
import Html exposing (Html, button, div, h1, input, text)
import Html.Events exposing (onClick, onInput)
html elm
1个回答
0
投票
import Browser import Html exposing (Html, button, div, h1, input, text) import Html.Events exposing (onClick, onInput)
似乎您已经知道如何导入表示单个html元素的函数,因此要解决img问题,只需将其添加到Html公开的导入列表中即可。至于src,就像代表HTML属性的所有函数一样,它来自Html.Attributes

因此只需将以上内容更改为:

import Browser import Html exposing (Html, button, div, h1, img, input, text) import Html.Events exposing (onClick, onInput) import Html.Attributes exposing (src)

© www.soinside.com 2019 - 2024. All rights reserved.