武汉今鱼乐娱网络
武汉今鱼乐娱网络
  • 发布:2025-02-25 17:32
  • 更新:2025-02-26 14:33
  • 阅读:43

请问uni_modules编写的【uts插件 - uni-app兼容模式组件】在uvue APP端,应该如何正确声明ref

分类:uni-app x
<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‌

请问应该怎么解决?

2025-02-25 17:32 负责人:无 分享
已邀请:
武汉今鱼乐娱网络

武汉今鱼乐娱网络 (作者) - 武汉软件开发公司,可实地考察

解决了,声明改成:DxUtsWebviewElement 就好了

要回复问题请先登录注册