Vue 3.x 可选的 props 声明
可选的 props 声明
When a component has no props
declarations, all attributes passed by the parent are exposed in this.$props
. Unlike declared props, they will NOT be exposed directly on this
. In addition, in this case this.$attrs
and this.$props
will be pointing to the same object.
<template>
<div>{{ $props.foo }}</div>
</template>
// If the component has no other options, the entire `<script>` block can be dropped, so the following would be a valid SFC
<script>
export default {}
</script>
函数式组件
Similar to stateful components, when props are declared, the props
arguments will only contain the declared props - attributes received but not declared as props will be in the argument ( attrs
):
const FunctionalComp = (props, slots, attrs) => {
// const FunctionalComp = (props, { slots, attrs }) => { 难道不是这样吗
// `attrs` contains all received attributes except declared `foo`
}
FunctionalComp.props = {
foo: Number
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
下一篇: TypeScript 常见问题
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论