1👍
Vue-Router
will not work in custom js file file like User.js
Use it in Vue Component. Like:
Register.vue
<template>
<div class="col-md-12">
<div class="card card-container">
<form name="form" @submit.prevent="handleRegister">
----
</form>
</div>
</template>
<script>
export default {
data() { return { user: {} }},
methods: {
handleRegister() {
this.registration();
});
},
registration() {
User.register(this.user);
this.$router.push({ name: 'Index'});
}
},
}
</script>
- [Vuejs]-How can my partials access the main data object in Vue?
- [Vuejs]-JS Promise in vue shows as undefined
0👍
The other answer is correct but what the case of the registration failure !, so try to add a callback as parameter then call it inside then :
class User {
register(data,cb) {
let uri = 'http://localhost:8000/api/auth/register';
let self = this;
Axios.post(uri, data).then((res) => {
cb()
}).catch( (error) => {
console.log(error);
});
}
}
registration() {
User.register(this.user, ()=>{this.$router.push({ name: 'Index'});});
}
- [Vuejs]-Why when i am sending blob in fetch i can download file but when i am using axios it will not work?
- [Vuejs]-What does const { Nuxt, Builder } = require('nuxt') mean
Source:stackexchange.com