unipluginDemo 安卓sdk中的示例项目, 添加了一个uts测试页面,添加一个uts组件,组件内就一个test方法, 然后nvue这边无论如何都无法调用这个test方法, 始终是报错,
TypeError: this.$refs.simpleView.test is not a function
<template>
<view class="content">
<!-- UTS自定义控件 -->
<uts-simple ref="simpleView"></uts-simple>
<!-- 按钮 -->
<button type="default" @click="onTestClick" class="action-button">测试Simple</button>
</view>
</template>
<script>
export default {
onLoad() {
console.log('页面加载完成');
},
methods: {
onTestClick() {
console.log('按钮被点击');
this.$refs.simpleView.test();
}
}
}
</script>
<style>
.content {
flex: 1;
align-items: center;
justify-content: center;
}
.action-button {
width: 300px;
height: 50px;
margin-top: 50px;
}
</style>
<template>
<view>
</view>
</template>
<script lang="uts">
export default {
name: "uts-simple",
data() {
return {}
},
// 显式暴露方法
expose: ['test'],
methods: {
test() {
console.log("UTS-Simple: test方法被调用");
}
},
created() {
console.log("UTS-Simple: created生命周期");
}
}
</script>
<style>
</style>
4 个回复
最佳回复
啊o额iu鱼 (作者)
通了,总之很多坑,
啊o额iu鱼 (作者)
直接使用官方文档的代码也一样,
https://doc.dcloud.net.cn/uni-app-x/plugin/uts-component-compatible.html
啊o额iu鱼 (作者)
问题在自定义基座,
我用的是android sdk打包的基座, uts就用不了, 标准基座就正常,
要怎么做才能在自定义基座使用uts?
啊o额iu鱼 (作者)
搞不懂, 不是基座问题, 标准基座能用的时候自定义基座也能用,
然后不知怎么突然又不行了, 怎么看都和代码无关,uts组件压根没能加载,也没有报错,