-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
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
warn if $set is used on a property that already exist #8129
Comments
You're setting 2 different this.$set(this, 'setCameLate', 'yes'); Please, next time consider using the forum, the Discord server or StackOverflow for questions first. But feel free to come back and open an issue if it turns out to be a bug 🙂 |
Sorry I messed the example up. Try read it again. Or you can read the source code of |
Im not sure I get your question, but vue cannot detect the assignment, so you need set. |
@posva I think what @JJPandari would like to do is use Vue.set(this.person, 'job', 'Educator') If
What do you think? |
seems fine. I also think it's hardly useful but a warning is ok |
@chrisvfritz Would you see this being logged to the browser console, or something that would be in the build process? Just thinking about taking a stab at this. |
it's a runtime dev only warning if you want to add it 🙂 |
…hat already exists. In development mode, warns if user tries to Vue.set a property that already exists. Issue reported in vuejs#8129. Codepen demonstrating the issue available at https://codepen.io/chrisvfritz/pen/rvzgBR?editors=1010 fix vuejs#8129
…ng set that already have been c fix vuejs#8129
I think there's a valid use case for setting $set on existing properties. In my application code I have a |
@fnlctrl It's a bit unclear the way this issue was initially worded, but Chris' codepen is a good example of the real issue here. https://codepen.io/chrisvfritz/pen/rvzgBR?editors=1010 JJPandari's real issue was that they created a non-reactive property then later called The pull request I added on this #8138 is also addressing only that usage of a call to set. In a non-production environment, it will check if you are trying to set a non-reactive property in which case you would get a warning that said property will not be reactive. |
I see... though there's another question: Why not just make it work too when there's already a non-reactive property? 😄 I don't see why there should be a limit. |
@fnlctrl My thinking was that if someone first creates an unreactive property, then tries to make it reactive later, any reference to that property in between those two events is very likely to create a difficult-to-diagnose bug. By showing a warning that they should make the property reactive from the start, we encourage a best practice that eliminates the window for bugs to occur. |
It's probably fixed but I'm not sure, haven't used vue recently. @posva Would you link the PR to this issue and close this if fixed? |
Does this problem still exist? |
Version
2.5.16
Reproduction link
https://codepen.io/JJPandari/pen/gzLVBq?editors=1010
Steps to reproduce
See the codepen snippet. Follow the comment there to change the vm's data and see what happens.
What is expected?
Even if the prop already exists, using
set
still makes it reactive, thus trigger view update.What is actually happening?
Using
set
later doesn't update the view.Related source code:
vue/src/core/observer/index.js
Line 192 in 3eb37ac
set
to make the prop reactive whenever it's used. I initially opened an issue for the api doc because it wasn't clear (for me) about this. But the comment in the source code is.The text was updated successfully, but these errors were encountered: