diff --git a/src/core/instance/state.js b/src/core/instance/state.js index 67f9dae381d..db0d8acd087 100644 --- a/src/core/instance/state.js +++ b/src/core/instance/state.js @@ -202,6 +202,8 @@ function initComputed (vm: Component, computed: Object) { warn(`The computed property "${key}" is already defined in data.`, vm) } else if (vm.$options.props && key in vm.$options.props) { warn(`The computed property "${key}" is already defined as a prop.`, vm) + } else if (vm.$options.methods && key in vm.$options.methods) { + warn(`The computed property "${key}" is already defined as a method.`, vm) } } } diff --git a/test/unit/features/options/computed.spec.js b/test/unit/features/options/computed.spec.js index edc20bad3bf..17cd9516640 100644 --- a/test/unit/features/options/computed.spec.js +++ b/test/unit/features/options/computed.spec.js @@ -206,6 +206,18 @@ describe('Options computed', () => { expect(`computed property "a" is already defined as a prop`).toHaveBeenWarned() }) + it('warn conflict with methods', () => { + new Vue({ + computed: { + a: () => 2 + }, + methods: { + a: () => {} + } + }) + expect(`computed property "a" is already defined as a method`).toHaveBeenWarned() + }) + it('rethrow computed error', () => { const vm = new Vue({ computed: {