Answer the question
In order to leave comments, you need to log in
How to continue executing code only after axios?
Good day everyone.
I hastily wrote this simple validator:
validateNewUserInfo() {
this.errors = [];
if(!this.newUserData.name) {
this.errors.push('Укажите имя');
}
if(!this.newUserData.lastName) {
this.errors.push('Укажите фамилию');
}
if(!this.newUserData.secondName) {
this.errors.push('Укажите отчество');
}
if(!this.newUserData.phone) {
this.errors.push('Укажите телефон');
}
if(!this.newUserData.password) {
this.errors.push('Укажите пароль');
}
if(!this.newUserData.login) {
this.errors.push('Укажите логин');
}
if(!this.newUserData.email) {
this.errors.push('Укажите почту');
} else if(!this.validMail(this.newUserData.email)) {
this.errors.push('Укажите корректный адрес электронной почты');
}
if(!this.newUserData.role) {
this.errors.push('Выберите роль');
}
var data = {};
data = {'login': this.newUserData.login};
axios.post('checkfield', {params: data}).then(response => {
if(response.data !== 1) {;
this.errors.push(response.data);
}
});
if(!this.errors.length) {
return true;
}
},
Answer the question
In order to leave comments, you need to log in
axios.post returns a promise, https://learn.javascript.ru/promise
after it becomes clear what it is, you can switch to async https://learn.javascript.ru/async-await
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question