Skip to content

Computed with set but no get causes exception #5265

@kmc059000

Description

@kmc059000

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions