props 是组件的「函数参数」:父组件通过属性把数据传进去,子组件只读使用——直接修改 props 是反模式(React 报错,Vue 报警告)。需要改,就让子组件 emit 事件、父组件改状态,数据流保持单向清晰。
props 支持默认值、类型校验、必填检查。Vue 用 defineProps 声明,React 用函数参数接收,两者都遵循「外部数据只读」这一铁律。
// Vue:声明式 props const props = defineProps({ title: { type: String, required: true }, count: { type: Number, default: 0 } }); // React:函数参数 function Card({ title, count = 0 }) { return <h2>{title}({count})</h2>; }