diff --git a/components/input-item/demo/cases/demo5.vue b/components/input-item/demo/cases/demo5.vue index 3501f5dae..d6dff0111 100644 --- a/components/input-item/demo/cases/demo5.vue +++ b/components/input-item/demo/cases/demo5.vue @@ -12,7 +12,6 @@ type="bankCard" title="储蓄卡号" v-model="bankCardNo" - :key="bankCardKey" clearable @blur="checkBankCard" > @@ -43,7 +42,6 @@ export default { data() { return { bankCardNo: '', - bankCardKey: Date.now(), isError: false, } }, @@ -54,7 +52,6 @@ export default { } else { this.isError = false } - this.bankCardKey = Date.now() }, bankCardTip() { Dialog.alert({ diff --git a/components/input-item/index.vue b/components/input-item/index.vue index c3511142e..6df54f953 100644 --- a/components/input-item/index.vue +++ b/components/input-item/index.vue @@ -6,8 +6,8 @@ isTitleLatent ? 'is-title-latent' : '', isInputActive ? 'is-active' : '', isInputFocus ? 'is-focus' : '', - isInputError ? 'is-error' : '', - isInputBrief ? 'with-brief' : '', + isInputError() ? 'is-error' : '', + isInputBrief() && !isInputError() ? 'with-brief' : '', isDisabled ? 'is-disabled': '', isAmount ? 'is-amount': '', clearable ? 'is-clear' : '', @@ -86,14 +86,14 @@

@@ -279,12 +279,6 @@ export default { isInputEmpty() { return !this.inputValue.length }, - isInputError() { - return this.$slots.error || this.error !== '' - }, - isInputBrief() { - return (this.$slots.brief || this.brief !== '') && !this.isInputError - }, isDisabled() { return this.rootField.disabled || this.disabled }, @@ -316,7 +310,6 @@ export default { } }, }, - created() { this.inputValue = this.$_formateValue(this.$_subValue(this.value + '')).value }, @@ -397,6 +390,12 @@ export default { return formateValue }, + isInputError() { + return this.$slots.error || this.error !== '' + }, + isInputBrief() { + return this.$slots.brief || this.brief !== '' + }, $_trimValue(val) { return trimValue(val, '\\s|,') }, diff --git a/components/input-item/test/index.spec.js b/components/input-item/test/index.spec.js index 9cb557cf6..c0bc9fc86 100644 --- a/components/input-item/test/index.spec.js +++ b/components/input-item/test/index.spec.js @@ -128,4 +128,41 @@ describe('InputItem - Operation', () => { input.trigger('click') }) + + test('should show error slot', async () => { + wrapper = mount({ + template: ` + +

+ errorMsg +

+
+ `, + components: { + [InputItem.name]: InputItem, + }, + data() { + return { + isError: false, + } + }, + }) + + expect(wrapper.contains('.md-input-item-msg')).toBe(false) + wrapper.vm.isError = true + await wrapper.vm.$nextTick(() => { + expect(wrapper.contains('.md-input-item-msg')).toBe(true) + expect(wrapper.find('.md-input-item-msg').text()).toBe('errorMsg') + }) + + wrapper.vm.isError = false + await wrapper.vm.$nextTick(() => { + expect(wrapper.contains('.md-input-item-msg')).toBe(false) + }) + }) })