Skip to content

docs: add note about object/array default values in defineModel#3410

Open
whysopaul wants to merge 2 commits into
vuejs:mainfrom
whysopaul:docs/model-defaults-note
Open

docs: add note about object/array default values in defineModel#3410
whysopaul wants to merge 2 commits into
vuejs:mainfrom
whysopaul:docs/model-defaults-note

Conversation

@whysopaul

Copy link
Copy Markdown
Contributor

Description of Problem

The v-model/defineModel documentation does not mention that object/array literals should be avoided as default values, and that wrapped functions should be used instead.

Quote from Typing Component Props - Props Default Values:

Note that default values for mutable reference types (like arrays or objects) should be wrapped in functions when using withDefaults to avoid accidental modification and external side effects. This ensures each component instance gets its own copy of the default value. This is not necessary when using default values with destructure.

Proposed Solution

Add a short note using the text from the quote above in a warning block to the following sections:

  1. Component v-model - Under the Hood
  2. API Reference - defineModel()

Also note that, as when using withDefaults with defineProps, default values for mutable reference types (like arrays or objects) should be wrapped in functions in defineModel to avoid accidental modification and external side effects.

Additional Information

Since v-model uses props/emits under the hood, this will help highlight the connection between them.

@netlify

netlify Bot commented Jun 16, 2026

Copy link
Copy Markdown

Deploy Preview for vuejs ready!

Name Link
🔨 Latest commit 9f806cd
🔍 Latest deploy log https://app.netlify.com/projects/vuejs/deploys/6a62377805f241000763d4d2
😎 Deploy Preview https://deploy-preview-3410--vuejs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Comment thread src/api/sfc-script-setup.md Outdated
Comment thread src/guide/components/v-model.md Outdated

@bencodezen bencodezen left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR @whysopaul! I recommended two tweaks to the phrasing to make it more concise. Let me know if you have questions or want to discuss it further.

Co-authored-by: Ben Hong <ben@bencodezen.io>
@whysopaul

Copy link
Copy Markdown
Contributor Author

Hello @bencodezen! Thanks for the comments. I've applied the suggested changes.

@whysopaul
whysopaul requested a review from bencodezen July 23, 2026 15:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants