Skip to content

Commit 3fc91b9

Browse files
committed
computed properties should be cached by default
1 parent b954689 commit 3fc91b9

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

src/instance/scope.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,11 +195,11 @@ exports._initComputed = function () {
195195
configurable: true
196196
}
197197
if (typeof userDef === 'function') {
198-
def.get = _.bind(userDef, this)
198+
def.get = makeComputedGetter(userDef, this)
199199
def.set = noop
200200
} else {
201201
def.get = userDef.get
202-
? userDef.cache
202+
? userDef.cache !== false
203203
? makeComputedGetter(userDef.get, this)
204204
: _.bind(userDef.get, this)
205205
: noop

test/unit/specs/instance/scope_spec.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,6 @@ describe('Instance Scope', function () {
180180
},
181181
// cached
182182
f: {
183-
cache: true,
184183
get: function () {
185184
spyF()
186185
return this.ff
@@ -192,7 +191,6 @@ describe('Instance Scope', function () {
192191
},
193192
// another cached, for watcher test
194193
h: {
195-
cache: true,
196194
get: function () {
197195
return this.hh
198196
}
@@ -305,6 +303,26 @@ describe('Instance Scope', function () {
305303
expect(vm.e).toBe('CDe')
306304
})
307305

306+
it('disable cache', function () {
307+
var external = { b: 'B' }
308+
var vm = new Vue({
309+
data: {
310+
a: 'A'
311+
},
312+
computed: {
313+
test: {
314+
cache: false,
315+
get: function () {
316+
return this.a + external.b
317+
}
318+
}
319+
}
320+
})
321+
expect(vm.test).toBe('AB')
322+
external.b = 'C'
323+
expect(vm.test).toBe('AC')
324+
})
325+
308326
})
309327

310328
describe('methods', function () {

0 commit comments

Comments
 (0)