在输入超过3个字符的情况下,这效果很好,我们有一个背景为negative
的自定义标签,但考虑到isValid
的外部验证,也可以使用其他任何内容.
<div id="q-app" style="min-height: 100vh;">
<div class="q-pa-md" style="max-width: 300px">
<p :class="!isValid && 'bg-negative'">Custom label</p>
<q-input
filled
v-model="model"
label="Type here"
bottom-slots
hint="Max 3 characters"
error-message="Please use maximum 3 characters"
:error="!isValid"
></q-input>
</div>
</div>
const { ref, computed } = Vue
const app = Vue.createApp({
setup () {
const model = ref('')
return {
model,
isValid: computed(() => model.value.length <= 3)
}
}
})
app.use(Quasar, { config: {} })
app.mount('#q-app')
这里是this part" rel="nofollow noreferrer">a codepen个带有视觉复制的文档,这取自this part个文档(外部验证).