<template>
<view class="page_root">
<dx-uts-webview :style="{width:width + 'px',height:height + 'px'}" ref="webview" @onLoadView="onLoadView"></dx-uts-webview>
</view>
</template>
<script setup>
// #ifdef APP-ANDROID
const width = uni.rpx2px(600);
const height = uni.rpx2px(800);
const url = ref("https://www.baidu.com/");
// const webview = ref<DxUtsWebviewComponentPublicInstance | null>(null);
const webview = ref<ComponentPublicInstance | null>(null);
function onLoadView() {
let params = {
url: url.value,
}
// webview.value?.$callMethod('setUrl', JSON.stringify(params))
webview.value?.$callMethod("setUrl")
console.log("onLoadView", webview.value);
}
// #endif
</script>
dx-uts-webview是我自定义的一个webview组件,里面有setUrl方法,原先在uniapp页面中可以用this.$refs.webview.setUrl调用。
现在如果声明webview 为ComponentPublicInstance ,就会报错 java.lang.ClassCastException: uts.sdk.modules.dxUtsWebview.DxUtsWebviewElement cannot be cast to io.dcloud.uniapp.vue.VueComponent
如果声明DxUtsWebviewComponentPublicInstance ,也会报错:
[plugin:uni:app-uts] 编译失败
17:25:47.856 error: None of the following functions can be called with the arguments supplied:
17:25:47.856 public fun <T> ref(value: TypeVariable(T)): Ref<TypeVariable(T)> defined in io.dcloud.uniapp.vue
17:25:47.856 public fun <T> ref(value: Ref<TypeVariable(T)>): Ref<TypeVariable(T)> defined in io.dcloud.uniapp.vue
17:25:47.857 public fun ref(value: UTSJSONObject): Ref<UTSJSONObject> defined in io.dcloud.uniapp.vue
17:25:47.857 public fun ref(value: Any?, flag: Number? = ...): Any defined in io.dcloud.uniapp.vue
17:25:47.857 public fun ref(value: Number): Ref<Number> defined in io.dcloud.uniapp.vue
请问应该怎么解决?
1 个回复
武汉今鱼乐娱网络 (作者) - 武汉软件开发公司,可实地考察
解决了,声明改成:DxUtsWebviewElement 就好了