File tree 2 files changed +26
-2
lines changed
2 files changed +26
-2
lines changed Original file line number Diff line number Diff line change @@ -216,13 +216,13 @@ export function defineComputed (
216
216
if ( typeof userDef === 'function' ) {
217
217
sharedPropertyDefinition . get = shouldCache
218
218
? createComputedGetter ( key )
219
- : userDef
219
+ : createGetterInvoker ( userDef )
220
220
sharedPropertyDefinition . set = noop
221
221
} else {
222
222
sharedPropertyDefinition . get = userDef . get
223
223
? shouldCache && userDef . cache !== false
224
224
? createComputedGetter ( key )
225
- : userDef . get
225
+ : createGetterInvoker ( userDef . get )
226
226
: noop
227
227
sharedPropertyDefinition . set = userDef . set || noop
228
228
}
@@ -253,6 +253,12 @@ function createComputedGetter (key) {
253
253
}
254
254
}
255
255
256
+ function createGetterInvoker ( fn ) {
257
+ return function computedGetter ( ) {
258
+ return fn . call ( this , this )
259
+ }
260
+ }
261
+
256
262
function initMethods ( vm : Component , methods : Object ) {
257
263
const props = vm . $options . props
258
264
for ( const key in methods ) {
Original file line number Diff line number Diff line change @@ -1076,6 +1076,24 @@ describe('SSR: renderToString', () => {
1076
1076
} )
1077
1077
} )
1078
1078
1079
+ // #8977
1080
+ it ( 'should call computed properties with vm as first argument' , done => {
1081
+ renderToString ( new Vue ( {
1082
+ data : {
1083
+ firstName : 'Evan' ,
1084
+ lastName : 'You'
1085
+ } ,
1086
+ computed : {
1087
+ fullName : ( { firstName, lastName } ) => `${ firstName } ${ lastName } ` ,
1088
+ } ,
1089
+ template : '<div>{{ fullName }}</div>' ,
1090
+ } ) , ( err , result ) => {
1091
+ expect ( err ) . toBeNull ( )
1092
+ expect ( result ) . toContain ( '<div data-server-rendered="true">Evan You</div>' )
1093
+ done ( )
1094
+ } )
1095
+ } )
1096
+
1079
1097
it ( 'return Promise' , done => {
1080
1098
renderToString ( new Vue ( {
1081
1099
template : `<div>{{ foo }}</div>` ,
You can’t perform that action at this time.
0 commit comments