mirror of
https://gitee.com/vuejs/vue.git
synced 2024-12-03 12:38:24 +08:00
feat(warn): warn computed conflict with methods (#10119)
Co-authored-by: wangzongxu <wangzongxu@vipkid.com.cn>
This commit is contained in:
parent
c6d7a6fce7
commit
3ad60fea73
@ -202,6 +202,8 @@ function initComputed (vm: Component, computed: Object) {
|
|||||||
warn(`The computed property "${key}" is already defined in data.`, vm)
|
warn(`The computed property "${key}" is already defined in data.`, vm)
|
||||||
} else if (vm.$options.props && key in vm.$options.props) {
|
} else if (vm.$options.props && key in vm.$options.props) {
|
||||||
warn(`The computed property "${key}" is already defined as a prop.`, vm)
|
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -206,6 +206,18 @@ describe('Options computed', () => {
|
|||||||
expect(`computed property "a" is already defined as a prop`).toHaveBeenWarned()
|
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', () => {
|
it('rethrow computed error', () => {
|
||||||
const vm = new Vue({
|
const vm = new Vue({
|
||||||
computed: {
|
computed: {
|
||||||
|
Loading…
Reference in New Issue
Block a user