HarmonyOS 鸿蒙Next:如何将class的事件回调给界面
HarmonyOS 鸿蒙Next:如何将class的事件回调给界面
网页会调用JsToJavaOnCreate,如何将class里的isCreate通知到CameraPage里的isCreate,我添加@Link报错了。
@Component
@Entry
struct CameraPage {
private controller: WebviewController = new webview.WebviewController()
@State link: string = ‘https:’
@State isCreate: boolean = false
@State javaObj: javaClass = new javaClass();
build() {
Stack() {
Web({ src: this.link, controller: this.controller })
.mixedMode(MixedMode.All)
.backgroundImage($r(‘app.media.background’))
.width(“100%”)
.height(“100%”)
.javaScriptAccess(true)
.domStorageAccess(true)
.fileAccess(true)
.imageAccess(true)
.onlineImageAccess(true)
.zoomAccess(true)
.overviewModeAccess(true)
.databaseAccess(true)
.geolocationAccess(true)
.multiWindowAccess(true)
.mediaPlayGestureAccess(true)
.blockNetwork(false)
.pinchSmooth(true)
.javaScriptProxy({
object: this.javaObj,
name: “android”,
methodList: [‘JsToJavaOnCreate’],
controller: this.controller
})
}
}
}
class javaClass {
isCreate: boolean = false
constructor() {
}
JsToJavaOnCreate(): string {
this.isCreate = true
return ‘’;
}
}
2 回复
在new javaClass()时,写成new javaClass(getContext(this))
然后在JsToJavaOnCreate里可以使用context.eventHub