question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

api doc: explicitly tell `set` only works when the prop doesn't exist yet

See original GitHub issue

Note: 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:closed
  • Created 5 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
chrisvfritzcommented, May 4, 2018

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. 🙂

0reactions
JJPandaricommented, May 4, 2018

I think this is more clear if anyone has the same doubt as me:

…This must be used at new property addition, using it after normal property addition (e.g. myObject.newProperty = 'hi') won’t make the property reactive.

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found