File tree 2 files changed +36
-6
lines changed
test/unit/features/options
2 files changed +36
-6
lines changed Original file line number Diff line number Diff line change @@ -183,14 +183,23 @@ function createComputedGetter (key) {
183
183
}
184
184
185
185
function initMethods ( vm : Component , methods : Object ) {
186
+ const props = vm . $options . props
186
187
for ( const key in methods ) {
187
188
vm [ key ] = methods [ key ] == null ? noop : bind ( methods [ key ] , vm )
188
- if ( process . env . NODE_ENV !== 'production' && methods [ key ] == null ) {
189
- warn (
190
- `method "${ key } " has an undefined value in the component definition. ` +
191
- `Did you reference the function correctly?` ,
192
- vm
193
- )
189
+ if ( process . env . NODE_ENV !== 'production' ) {
190
+ if ( methods [ key ] == null ) {
191
+ warn (
192
+ `method "${ key } " has an undefined value in the component definition. ` +
193
+ `Did you reference the function correctly?` ,
194
+ vm
195
+ )
196
+ }
197
+ if ( props && hasOwn ( props , key ) ) {
198
+ warn (
199
+ `method "${ key } " has already been defined as a prop.` ,
200
+ vm
201
+ )
202
+ }
194
203
}
195
204
}
196
205
}
Original file line number Diff line number Diff line change @@ -306,6 +306,27 @@ describe('Options props', () => {
306
306
expect ( 'already declared as a prop' ) . toHaveBeenWarned ( )
307
307
} )
308
308
309
+ it ( 'should warn methods already defined as a prop' , ( ) => {
310
+ new Vue ( {
311
+ template : '<test a="1"></test>' ,
312
+ components : {
313
+ test : {
314
+ template : '<div></div>' ,
315
+ props : {
316
+ a : null
317
+ } ,
318
+ methods : {
319
+ a ( ) {
320
+
321
+ }
322
+ }
323
+ }
324
+ }
325
+ } ) . $mount ( )
326
+ expect ( `method "a" has already been defined as a prop` ) . toHaveBeenWarned ( )
327
+ expect ( `Avoid mutating a prop directly` ) . toHaveBeenWarned ( )
328
+ } )
329
+
309
330
it ( 'treat boolean props properly' , ( ) => {
310
331
const vm = new Vue ( {
311
332
template : '<comp ref="child" prop-a prop-b="prop-b"></comp>' ,
You can’t perform that action at this time.
0 commit comments