这节课,我们来看下,怎么将一个 props 限制在一个特定的值的集合中。
假设,我们有一个 Image 组件,内容如下:
import { ref, computed } from 'vue'
const props = defineProps({
imgStyle: {
type: String,
default: 'square',
},
})
const computeImgStyle = computed(() => {
return {
square: props.imgStyle === 'square',
rounded: props.imgStyle === 'rounded',
}
})
.image {