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
Computed with set but no get causes exception #5265
Comments
Ignore this and view the PR below instead vue/src/core/instance/state.js Line 150 in 59a3722
I think that if you add the following to initComputed(), it will better handle this scenario.
I'll formalize this with a PR soon. |
13 tasks
kmc059000
added a commit
to kmc059000/vue
that referenced
this issue
Mar 23, 2017
Closing in favor of the PR. |
yyx990803
pushed a commit
that referenced
this issue
Mar 27, 2017
awamwang
pushed a commit
to awamwang/vue
that referenced
this issue
Jun 15, 2017
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Version
2.2.4
Reproduction link
http://codepen.io/anon/pen/gmKpNj?editors=1111
Steps to reproduce
Create a component with a computed which has a setter but does not have a getter. In my example, you get an exception in the console and the page does not render
What is expected?
Preferably a better error message or warning from Vue rather than an uncaught exception.
Or for backwards compatibility with Vue 2.1.8, have Vue allow a component to have a computed with no getter.
What is actually happening?
Receiving an console error and vue does not render anything.
Uncaught TypeError: Cannot read property 'toString' of undefined
at new Watcher (vue.js:2417)
at initComputed (vue.js:2743)
at initState (vue.js:2652)
at VueComponent.Vue._init (vue.js:3696)
at new VueComponent (vue.js:3862)
at createComponentInstanceForVnode (vue.js:3080)
at init (vue.js:2888)
at createComponent (vue.js:4579)
at createElm (vue.js:4522)
at createChildren (vue.js:4647)
This did not cause any exceptions in vue 2.1.8 and the component rendered and worked correctly.
This is code written by my coworker, and after upgrading vue today, this page was broken. I don't understand why it was written the way it was, and I do not think that the get is ever used, while the set is. It seems nonsensical to me to have code like this, but it exists. The problem is it took quite a while to hunt down why this was happening.
I can imagine a potential scenario where a developer misspells "get" and receives this error without any warning why, and is similarly confused on how to fix it.
The text was updated successfully, but these errors were encountered: