Skip to content
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

In the development environment, a warning will be output when some property values ​​are undefined #5784

Closed
maiomiaoh opened this issue Apr 22, 2022 · 5 comments

Comments

@maiomiaoh
Copy link

Version

3.2.33

Reproduction link

https://sfc.vuejs.org/

image

Steps to reproduce

<template>
  <input v-bind="props" />
</template>

<script setup>
const props = defineProps({
  size: Number,
})
console.log('props', props)
</script>

What is expected?

do not print warnings

What is actually happening?

[Vue warn]: Failed setting prop "size" on : value 0 is invalid.
Error: Failed to set the 'size' property on 'HTMLInputElement': The value provided is 0, which is an invalid size.

@maiomiaoh
Copy link
Author

same problem as #5734

@posva
Copy link
Member

posva commented Apr 22, 2022

This is native behavior:

Screenshot 2022-04-22 at 20 28 54

Your props object has a property of size being undefined so it sets it and it produces that warning. Ensure the object passed to v-bind has a correct size property.

See issues like #3576

@posva posva closed this as completed Apr 22, 2022
@maiomiaoh
Copy link
Author

Yeah~I know that, but shouldn't it be ignored if the property's value is undefined? Because a property with value undefined has no meaning

@posva
Copy link
Member

posva commented Apr 22, 2022

No, because some DOM properties could be expecting undefined as a possible value. You can and probably should reformat the object passed to v-bind in order to ensure valid values. As an example: you wouldn't pass :size="size" if size could be null or 0.

You can force it as an attribute to remove it though.

@maiomiaoh
Copy link
Author

Thanks! I didn't know has .attr modifier

@github-actions github-actions bot locked and limited conversation to collaborators Sep 29, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants