так сложно получить ответ от BACKEND, потому что есть много изменений IN Front END , что делает его таким трудным,
Мне нужно, как получить сообщение об ошибке на основеИмя поля в начале, это ответ от 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