Vue:
https://cn.vuejs.org/v2/guide/components-props.html#Prop-%E9%AA%8C%E8%AF%81
props:{
属性名称:{
type:'',
required:true,
default:xxx
}
}
React:【PropTypes】
https://zh-hans.reactjs.org/docs/typechecking-with-proptypes.html
两个静态属性 (或者实例属性)
defaultProps 设置默认值
propTypes 类型检查
import React, { Component } from 'react';
import PropTypes from 'prop-types'
class PropsType extends Component {
//实例属性定义
static propTypes = {
name:PropTypes.string.isRequired,
age:PropTypes.number
}
static defaultProps = {
age: 100
}
render() {
return (
<div>
{this.props.name}---{this.props.age}
</div>
);
}
}
// 静态属性定义
// PropsType.propTypes = {
// name:PropTypes.string.isRequired,
// age:PropTypes.number
// }
export default PropsType;