-
-
Notifications
You must be signed in to change notification settings - Fork 8.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve the props parameter in setup function #3288
Comments
How would you differentiate a prop passed as Wouldn't make more sense to do: const foo = toRef(props, 'foo') Edit: Although this is technically a breaking change, having the key with |
If a {
props: {
foo: {
type: String
}
},
setup(props) {
console.log(Object.keys(props)) // []
const { foo } = toRefs(props) // foo is `undefined`
}
} So I think it is as expected |
@posva Hmmm this is a valid point. Maybe we do need to use @HcySunYang I think @posva is right if we always provide So maybe we should only use |
What would be the use case for an optional prop that wasn't passed in to the component? <my-comp/>
<my-comp :foo="undefined"/>
<script>
props : {
foo: String
}
</script> That code should behave the same. This behaviour gets really inconsistent when you use a This behaviour is different from v2 options API with options API the properties will always be defined. // vue2
{
props: {
foo: String
},
data(){
return {
hasKey: 'foo' in this.$props // true
}
}
}
// vue3
{
props: {
foo: String
},
data(){
return {
hasKey: 'foo' in this.$props // false
}
}
} Altho I still dont know the use case for handling an optional property without default (aka |
After some discussion with @pikax I think this issue should be reopened. As with current implementation, we actually cannot reliably detect missing props with a simple |
This did break prop pass detection that I was relying on as reported in logaretm/vee-validate#3294 As a workaround I had introduced a symbol as a default value to detect when the user didn't pass the prop: export const EMPTY_VALUE = Symbol('Default empty value');
``
```js
{
modelValue: {
type: null,
default: EMPTY_VALUE,
},
} This should probably be marked as a breaking change in the changelog. |
What problem does this feature solve?
Instead, we need to use:
So we need to switch to
props.foo
whenever we need to watch it, which doesn't feel very natural to me.What does the proposed API look like?
For all declared props, always provide
{ [propName]: undefined }
in theprops
parameter of thesetup
function so that we can write:The text was updated successfully, but these errors were encountered: