基于API响应,突出显示了特定的输入红/无效
基于API依据
我抓住了它并显示了一个红色警报,但最重要的是,我也想触发红色亮点 name Input 。
我的输入
<v-text-field
:class="{ 'invalid' : invalidName }"
dense
outlined
v-model="name"
:rules="form.rules.name"
label="Name"
required
></v-text-field>
CSS
>>> .invalid .v-label {
color: #b13737 !important;
caret-color: #ff5252 !important;
}
>>> .invalid input {
color: #b13737 !important;
caret-color: #ff5252 !important;
}
>>> .invalid .v-text-field--outlined fieldset {
border: 2px solid #b13737 !important;
}
捕获
this.invalidName = true //turned it to true when error detected
this.alert = true
this.alertColor = 'red'
this.alertMessage = response.data.error.detail
结果
我只能将标签和文本的颜色和颜色变
Based on the API reponse
I caught it and display a red alert, but on top of that, I would like to also trigger red highlight to the name input.
my input
<v-text-field
:class="{ 'invalid' : invalidName }"
dense
outlined
v-model="name"
:rules="form.rules.name"
label="Name"
required
></v-text-field>
css
>>> .invalid .v-label {
color: #b13737 !important;
caret-color: #ff5252 !important;
}
>>> .invalid input {
color: #b13737 !important;
caret-color: #ff5252 !important;
}
>>> .invalid .v-text-field--outlined fieldset {
border: 2px solid #b13737 !important;
}
catch it
this.invalidName = true //turned it to true when error detected
this.alert = true
this.alertColor = 'red'
this.alertMessage = response.data.error.detail
result
I can only turn label and the color of the text red
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有时候,Vuetify的CSS有些棘手。尝试这样做:
Override vuetify's css can be a little tricky sometimes. Try doing it like this:
不要与Vuetify输入错误状态CSS手动混乱。而是尝试使用
错误
(boolean)和error-messages
(字符串或数组)((如果您不隐藏详细信息)) 。如果您可以在响应中解析错误,我建议构建一个inputErrors对象,其中键是字段的名称和值是(可能)错误消息。特别是如果您在一个提交中显示多个错误字段。
您可以用
.split(':':')
对data.err.Error.Error.Errer.Erferion
进行解析,然后使用索引[0]作为上述inputErrors对象的键和index [1]值。然后,您可以通过编程使用文本字段的错误道具。
您可能不需要两者。如果错误消息不是null,则可能是错误状态为true。
Don't mess with the Vuetify input error state CSS manually. Instead try to make use of the
error
(boolean) anderror-messages
(string or array) ((if you are not hiding details)) props of the text-field.If you can parse the error in the response, I would recommend constructing an inputErrors object, where the keys are the names of the fields and values are (possibly) the error message(s). Especially if you would show multiple error fields in one submission.
You could parse
data.error.reference
with.split(':')
and use index [0] as the key of the above inputErrors object and index [1] as the value.Then you can use the error props of the text-field programatically.
It's possible you don't need both. It might be the case if error-messages is not null the error state is true.