在Kotlin和React中使用图像 [英] Using image with Kotlin and React

查看:50
本文介绍了在Kotlin和React中使用图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用create-react-kotlin-app创建了此网页.xml与我以前使用的XML不同,并且我确实在使用与index.kt位于同一目录中的徽标而苦苦挣扎.我该如何解决?

I created this webpage with create-react-kotlin-app. The xml is different than I'm used to and I'm really struggling using a logo that is in the same directory as index.kt. How can I fix this?

package index

import react.dom.*
import kotlin.browser.*

fun main(args: Array<String>) {

    val rootDiv = document.getElementById("root")

    render(rootDiv) {
        img(src="./logo.jpg"){}
    }
}

推荐答案

好吧,我只是通过查看create-react-kotlin-app默认内容(有点尴尬)找到了解决方案.

Ok, I found a solution simply by taking a look at the create-react-kotlin-app default content, a little awkward.

package index

import react.dom.*
import kotlin.browser.*

@JsModule("src/resources/logo.jpg")
external val logo: dynamic

fun main(args: Array<String>) {

    val rootDiv = document.getElementById("root")

    render(rootDiv) {
        img(src = logo){}
    }
}

如果您问我,那将是不必要的麻烦.

Unnecessarily cumbersome if you ask me.

这篇关于在Kotlin和React中使用图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆