api doc: explicitly tell `set` only works when the prop doesn't exist yet
See original GitHub issueNote: Here I’m all talking about a prop that doesn’t exist in data
in the first place.
The api says:
If the object is reactive, ensure the property is created as a reactive property and trigger view updates.
At least for me, it’s not clear “does set
work if the prop isn’t in data
, and I’ve already added it diredtly without set
?”. So I tried the source code and the comment made it clear:
Adds the new property and triggers change notification if the property doesn’t already exist.
Then I altered my code to use set
at prop addition and the not-properly-re-rendering problem was fixed.
So I think it may be better to explicitly tell in the api that set
only works when the prop doesn’t exist yet? Like the comment does?
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
How do you explicitly set a new property on `window` in ...
I can make the code work by declaring MyNamespace as an ambient variable and dropping the window explicitness but I don't want to...
Read more >Fluent API - Configuring and Mapping Properties and Types
Configuring a Primary Key To explicitly set a property to be a primary key, you can use the HasKey method. In the following...
Read more >.prop() | jQuery API Documentation
The .prop() method gets the property value for only the first element in the matched set. It returns undefined for the value of...
Read more >Optional chaining (?.) - JavaScript - MDN Web Docs - Mozilla
Optional chaining with function calls You can use optional chaining when attempting to call a method which may not exist.
Read more >Working with routes for HTTP APIs - Amazon API Gateway
When the $default route receives a request, API Gateway sends the full request path to the integration. For example, you can create an...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Excellent! I just made that update to the docs. I also left a comment on your issue. I don’t think
Vue.set
should work to make existing properties reactive, because not doing it initially leaves open a window for bugs. I do agree we can improve the experience, however, and suggested that Vue emit a warning instead so that users know what they’ve done wrong. 🙂I think this is more clear if anyone has the same doubt as me:
Somehow I feel this behavior itself is not intuitive. I’ve opened an issue for vue, let’s see what people say about that then.