Answer the question
In order to leave comments, you need to log in
How to make a component re-render when routed?
This is a router
import {apiGetUser} from "../api/api";
import Vue from 'vue';
import VueRouter from 'vue-router';
Vue.use(VueRouter);
const router = new VueRouter({
mode: 'history',
base: "quiz/",
routes: [
{
path: "/:step([1-9]{1}|[1-9]{2})",
name: "step",
component: () => import('../components/Question.vue'),
beforeEnter: async (to, from, next) => {
const user = await apiGetUser();
if (user.data.data.ended) {
return next({ name: 'finish' });
}
if (user.data.data.step !== to.params.step) {
return next({ name: 'step', params: {step: user.data.data.step} });
}
return next();
}
}
],
});
export default router;
methods: {
next: async function (e) {
const data = new FormData(e.target);
// console.log(this.$router)
const response = await apiQuestion('POST', this.$route.params.step, data);
if (response.data.success){
console.log('new step', this.$route.params.step + 1);
this.$router.push({
name: 'step',
params: {
step: this.$route.params.step + 1
}
})
.catch(error =>{
console.log(error);
});
}
if(!response.data.success){
this.$toast.error(response.data.message);
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question