The left-hand side of an arithmetic operation must be of type ‘any’, ‘number’, ‘bigint’ or an enum type.
props: {
width: {
type: Number,
default: 800,
},
height: {
type: Number,
default: 300,
},
}
const ratio = computed(() => props.height / props.width)
两种解决方法
其一,声明一个PropsInterface跟props的属性重叠,赋值给setup的props,如果有多个number的props肯定推荐这个
interface CanvasProps {
width: number
height: number
}
setup(props:CanvasProps){}
其二用Number强制转换为number
const ratio = computed(() => Number(props.height) / Number(props.width))
或者,就是太丑了
const ratio = computed(() => props.height as number/ (props.width as number))