Skip to content

tree示例算不算违背单向数据流? #3208

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

Open
wrong-g opened this issue Mar 29, 2025 · 1 comment
Open

tree示例算不算违背单向数据流? #3208

wrong-g opened this issue Mar 29, 2025 · 1 comment

Comments

@wrong-g
Copy link

wrong-g commented Mar 29, 2025

https://cn.vuejs.org/guide/components/props.html#mutating-object-array-props

Image

@dariasavinova
Copy link
Contributor

Hi. I agree with the issue that in the Tree Example, there are direct mutations of props - specifically, props.model.children.push(...) and props.model.children = []. This violates Vue’s principle of one-way data flow, where props are meant to be treated as immutable.

It's likely that this approach was chosen intentionally to keep the example concise and focused.
However, it might be beneficial to either:

  • include a comment in the example clarifying that the prop mutation is used for simplicity and not recommended in production code, or
  • update the example to follow Vue’s best practices, using local state or event emission instead.

I can help refactor the example if needed. What do you think?

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

No branches or pull requests

2 participants