modelValue的类型在uni-app中应该怎么设置
modelValue的类型在uni-app中应该怎么设置
| 开发环境 | 版本号 | 项目创建方式 |
|---|---|---|
| Windows | win10 | HBuilderX |
产品分类:uni-app x/App
PC开发环境操作系统:Windows
HBuilderX类型:正式
HBuilderX版本号:4.76
手机系统:Android
手机系统版本号:Android 16
手机厂商:小米
手机机型:k70e
页面类型:vue
vue版本:vue3
打包方式:云端
项目创建方式:HBuilderX
操作步骤:
1
预期结果:
1
实际结果:
1
bug描述:
modelValue: {
type: [Object, String, Number, Array],
default: ''
},
const emit = defineEmits([
'update:modelValue'
])
// 会报错:
emit('update:modelValue', 111)
error: java.lang.IllegalArgumentException: method uni.xxx.GenPagesTabbarHome$Companion$setup$1$8$1$6$5$1.invoke argument 1 has type io.dcloud.uniapp.vue.Ref, got java.lang.Integer
更多关于modelValue的类型在uni-app中应该怎么设置的实战教程也可以访问 https://www.itying.com/category-93-b0.html
1 回复
更多关于modelValue的类型在uni-app中应该怎么设置的实战教程也可以访问 https://www.itying.com/category-93-b0.html
在 uni-app x 中,modelValue 的类型定义需要更严格。从错误信息看,问题在于你定义了多种类型,但实际使用时类型不匹配。
建议修改为:
// 方案1:明确指定单一类型
modelValue: {
type: Number,
default: 0
}
// 或者方案2:使用泛型
const props = defineProps<{
modelValue: number
}>()
const emit = defineEmits<{
'update:modelValue': [value: number]
}>()

