Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(warn): warn computed conflict with methods #10119

Merged
merged 1 commit into from Apr 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/core/instance/state.js
Expand Up @@ -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)
}
}
}
Expand Down
12 changes: 12 additions & 0 deletions test/unit/features/options/computed.spec.js
Expand Up @@ -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: {
Expand Down