Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 3ad60fe

Browse files
hou-puwangzongxu
and
wangzongxu
authoredApr 16, 2021
feat(warn): warn computed conflict with methods (#10119)
Co-authored-by: wangzongxu <wangzongxu@vipkid.com.cn>
1 parent c6d7a6f commit 3ad60fe

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed
 

‎src/core/instance/state.js

+2
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,8 @@ function initComputed (vm: Component, computed: Object) {
202202
warn(`The computed property "${key}" is already defined in data.`, vm)
203203
} else if (vm.$options.props && key in vm.$options.props) {
204204
warn(`The computed property "${key}" is already defined as a prop.`, vm)
205+
} else if (vm.$options.methods && key in vm.$options.methods) {
206+
warn(`The computed property "${key}" is already defined as a method.`, vm)
205207
}
206208
}
207209
}

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

+12
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,18 @@ describe('Options computed', () => {
206206
expect(`computed property "a" is already defined as a prop`).toHaveBeenWarned()
207207
})
208208

209+
it('warn conflict with methods', () => {
210+
new Vue({
211+
computed: {
212+
a: () => 2
213+
},
214+
methods: {
215+
a: () => {}
216+
}
217+
})
218+
expect(`computed property "a" is already defined as a method`).toHaveBeenWarned()
219+
})
220+
209221
it('rethrow computed error', () => {
210222
const vm = new Vue({
211223
computed: {

0 commit comments

Comments
 (0)
Failed to load comments.