子组件
function getSum(num: number): number {
return Math.round(num * 10)
}
// 才能将方法挂载在子组件实例上
defineExpose({ getSum })
父组件
const son = ref<InstanceType<typeof Son>>()
const changeNum = () => {
num.value = son.value?.getSum(Math.random() * 10) as number
}
这么看着没有问题,也能执行,但是在打包的时候……
"build": "vue-tsc --noEmit && vite build",
我知道的解决办法:
方法一:加上any
const son = ref<InstanceType<typeof Son> | any>()
方法二就是去掉打包时候的类型校验
"build": "vite build",
但是这两个方法本质都是跳过类型校验了
还有大神有更好的方法吗???