Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
forked fromvuejs/vue

Commit613cb52

Browse files
Stexxeyyx990803
authored andcommitted
polish: improve invalid method warning with type info (vuejs#8974)
closevuejs#8017
1 parenta7658e0 commit613cb52

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

‎src/core/instance/state.js‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,9 +257,9 @@ function initMethods (vm: Component, methods: Object) {
257257
constprops=vm.$options.props
258258
for(constkeyinmethods){
259259
if(process.env.NODE_ENV!=='production'){
260-
if(methods[key]==null){
260+
if(typeofmethods[key]!=='function'){
261261
warn(
262-
`Method "${key}" hasan undefined value in the component definition. `+
262+
`Method "${key}" hastype "${typeofmethods[key]}" in the component definition. `+
263263
`Did you reference the function correctly?`,
264264
vm
265265
)
@@ -277,7 +277,7 @@ function initMethods (vm: Component, methods: Object) {
277277
)
278278
}
279279
}
280-
vm[key]=methods[key]==null ?noop :bind(methods[key],vm)
280+
vm[key]=typeofmethods[key]!=='function' ?noop :bind(methods[key],vm)
281281
}
282282
}
283283

‎test/unit/features/options/methods.spec.js‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ describe('Options methods', () => {
1919
expect(vm.a).toBe(2)
2020
})
2121

22-
it('should warnundefinedmethods',()=>{
22+
it('should warn methods of not function type',()=>{
2323
newVue({
2424
methods:{
25-
hello:undefined
25+
hello:{}
2626
}
2727
})
28-
expect(`Method "hello" hasan undefined valuein the component definition`).toHaveBeenWarned()
28+
expect('Method "hello" hastype "object"in the component definition').toHaveBeenWarned()
2929
})
3030

3131
it('should warn methods conflicting with data',()=>{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp