Excuse me, Why always use `async/await` on Vue Method?
thearabbit opened this issue · comments
methods: {
async submit() {
await this.$validator.validateAll();
const { email, password } = this;
if (!this.isValid) {
return;
}
this.status = { submitTitle: 'Logging you in...', color: 'default' };
await this.$store.dispatch('login', { email, password })
.catch((error) => {
this.status = { submitTitle: 'Oops! Something went wrong...', color: 'error', dark: true };
this.error = error;
});
},
I use normal style, I still work fine
The reason I use async await is that it makes my code a bit more readable since I don't have to nest. The alternative for example for this line await this.$validator.validateAll();
would be:
return this.$validator.validateAll()
.then(() => this.$store.dispatch('login'));
In the end it just depends on use-case and what reads better, because they do the same thing
thanks 💯 .
Should we use async/await
on Meteor Method
or not?
You don't have to. Meteor methods are still callback based, but there are packages that help you with this