详解Vue内部怎样处理props选项的多种写法

2020-06-14 06:27:00易采站长站整理

经过这个函数之后,props 将被规范为:


props: {
team:{
type: null
}
}

假如我的 props 是一个对象:


props: {
name: String,
height: {
type: Number,
default: 198
}
}

经过这个函数之后,将被规范化为:


props: {
name: {
type: String
},
height: {
type: Number,
default: 198
}
}

注:对象的写法也分为以下两种,故仍需进行规范化


props: {
// 第一种写法,直接写类型
name: String,
// 第二种写法,写对象
name: {
type: String,
default: 'Kobe Bryant'
}
}

最终会被规范为第二种写法。