【问题标题】:Create React apps using Kotlin and External使用 Kotlin 和 External 创建 React 应用程序
【发布时间】:2018-10-24 07:46:25
【问题描述】:

我正在尝试封装这个简单的 API:https://github.com/github-tools/github,仅用于学习目的。所以,我创建了这个外部类:

package index

import com.github.jesty.githubapi.Result
import com.github.jesty.githubapi.User
import kotlin.js.Promise

external class GitHub(user: User) {
    fun getUser(): GHUser
}

external class GHUser {
    fun listStarredRepos(): Promise<Result>
}

在一个简单的 KotlinJS 项目中一切正常,但是当我尝试在使用 Create React Kotlin App 创建的项目中使用时,出现以下错误:

ReferenceError: GitHub is not defined 

【问题讨论】:

    标签: javascript reactjs kotlin kotlin-js


    【解决方案1】:

    刚刚解决了,需要用@JsModule("github-api")注解外部类:

    package com.github.jesty.githubapi
    
    import kotlin.js.Promise
    
    @JsModule("github-api")
    external class GitHub(user: User) {
        fun getUser(): GHUser
    }
    
    @JsModule("github-api")
    external class GHUser {
        fun listStarredRepos(): Promise<Result>
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-09-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多