validation - nuxt 中的验证后端获取
问题描述
很难从后端获取数据响应,因为前端有很多修改,这让我很难做到,
我需要如何根据前端的字段名称获取错误消息,这是来自 BACKEND 的响应
{
"status": false,
"created_at": "2018-11-12 22:47:28",
"error_message": "bad request",
"service": "request_validation",
"data": [
{
"field": "username",
"value": "fred@",
"message": "only contain ascii letters (a-zA-Z), ascii number characters (0-9) and single hyphens (-), and cannot begin or end with a hyphen are allowed"
},
{
"field": "password",
"value": "aaaa",
"message": "number of characters min 8 and max 30"
},
{
"field": "confirm_password",
"value": "aaaa",
"message": "number of characters min 8 and max 30"
}
]
}
这是我的 html,我不知道如何获取消息错误,
<div class="mb-20">
<form
id="form-register"
method="post"
@submit.prevent="onSubmit()"
<div class="mb-10">
<input
v-model="input.username"
type="text"
class="form-control border-bottom w-100"
placeholder="Username*"
name="username"
>
<label class="error">
<!-- error should fetch in here -->
</label>
</div>
<div class="mb-10">
<input
v-model="input.email"
type="email"
class="form-control border-bottom w-100"
placeholder="Email*"
name="email"
>
<label class="error">
<!-- error should fetch in here -->
</label>
</div>
<div class="mb-10">
<input
v-model="input.password"
type="password"
class="form-control border-bottom w-100"
placeholder="Password*"
name="password"
ref="password">
<label class="error">
<!-- error should fetch in here -->
</label>
</div>
<div class="mb-10">
<input
v-model="input.confirm_password"
type="password"
class="form-control border-bottom w-100"
placeholder="Confirm Password*"
name="confirm_password"
>
<label class="error">
<!-- error should fetch in here -->
</label>
</div>
<div class="text-center">
<button
type="submit"
class="btn-primary border-radius-30px"
@click="submitted=true" :disabled="submitted"
>Register
</button>
</div>
</form>
</div>
export default {
layout: 'LayoutLogRegFor',
data() {
return {
input: {
username: '',
email: '',
password: '',
confirm_password: '',
},
submitted:false
}
},
components: {
VueRecaptcha
},
computed: mapGetters({
user: 'user/user'
}),
getField(field){
// get message
},
methods: {
...mapActions({
postRegister: 'user/postRegister'
}),
onSubmit() {
await this.postRegister(this.input)
if (this.user.status === true && this.user.data.active == true) {
this.$router.push('/dashboard')
} else if (this.user.status === true && this.user.data.active == false) {
this.$router.push('/confirmation')
}
}
},
head() {
return {
bodyAttrs: {
class: 'register-section'
}
}
}
}
我的问题是如何在 html 中获取 nuxtjs 中的每个字段
解决方案
推荐阅读
- python - 将数组元素明智地组合以形成坐标数组
- html - 如何使用 CSS 使图像滑块重复为无限循环或选取框
- python - 通过在 Python 中跳过一个字符串来制作两列?
- c++ - MSVC 可以找到匹配的构造函数,但 gcc 和 clang 找不到
- android - 如何显示较小的视频文件比较大的视频文件流速度更快?
- unity3d - 将精灵隐藏在墙后,但当它在墙前时显示,Unity
- mysql - 如何使用查询获取关系子组件?
- java - 无符号右移运算符用作正常的右移运算符,为什么?
- c++ - 使用 Xcode 和 C/C++ 同时进行静态库和应用程序开发的正确配置
- wordpress - 无法修改标题信息 - 更新页面问题