@@ -172,18 +172,15 @@ function initComputed (vm: Component, computed: Object) {
172
172
173
173
for ( const key in computed ) {
174
174
const userDef = computed [ key ]
175
- let getter = typeof userDef === 'function' ? userDef : userDef . get
176
- if ( process . env . NODE_ENV !== 'production' ) {
177
- if ( getter === undefined ) {
178
- warn (
179
- `No getter function has been defined for computed property "${ key } ".` ,
180
- vm
181
- )
182
- getter = noop
183
- }
175
+ const getter = typeof userDef === 'function' ? userDef : userDef . get
176
+ if ( process . env . NODE_ENV !== 'production' && getter == null ) {
177
+ warn (
178
+ `Getter is missing for computed property "${ key } ".` ,
179
+ vm
180
+ )
184
181
}
185
182
// create internal watcher for the computed property.
186
- watchers [ key ] = new Watcher ( vm , getter , noop , computedWatcherOptions )
183
+ watchers [ key ] = new Watcher ( vm , getter || noop , noop , computedWatcherOptions )
187
184
188
185
// component-defined computed properties are already defined on the
189
186
// component prototype. We only need to define computed properties defined
@@ -214,6 +211,15 @@ export function defineComputed (target: any, key: string, userDef: Object | Func
214
211
? userDef . set
215
212
: noop
216
213
}
214
+ if ( process . env . NODE_ENV !== 'production' &&
215
+ sharedPropertyDefinition . set === noop ) {
216
+ sharedPropertyDefinition . set = function ( ) {
217
+ warn (
218
+ `Computed property "${ key } " was assigned to but it has no setter.` ,
219
+ this
220
+ )
221
+ }
222
+ }
217
223
Object . defineProperty ( target , key , sharedPropertyDefinition )
218
224
}
219
225
0 commit comments