Answer the question
In order to leave comments, you need to log in
How to force vuejs to reload a component?
Added a question.
There is such a component
var testComponent = Vue.component('main-section', (resolve) => {
axios.post('/test.php').then( (res) => {
resolve({
template: res.data,
mounted: () => {
console.log('mounted-' + new Date().getTime());
}
});
});
});
var router = new VueRouter({
routes: [
{ path: '/foo', component: testComponent },
{ path: '/bar', component: testComponent },
{ path: '*', component: testComponent }],
mode: 'history'
});
<router-link to="/foo"></router-link>
<router-link to="/bar"></router-link>
<router-link to="/somelink"></router-link>
<section class="content">
<router-view :key="$route.fullPath"></router-view>
</section>
Answer the question
In order to leave comments, you need to log in
//App.vue
<template>
<div id="app">
<router-link to="/random/12323jlwe">12323jlwe</router-link>|
<router-link to="/random/cxz98c7zf8a">cxz98c7zf8a</router-link>|
<router-link to="/random/90cvuiwa-r">90cvuiwa-r</router-link>
<section class="content">
<router-view :key="$route.fullPath"></router-view>
</section>
</div>
</template>
//main.js
import Vue from "vue";
import Router from "vue-router";
import App from "./App.vue";
Vue.use(Router);
var testComponent = Vue.component("main-section", {
template: `<component :is="template"></component>`,
data() {
return {
template: Vue.compile("<div>please stand by</div>")
};
},
created() {
// axios.post...
setTimeout(() => {
this.template = Vue.compile(`<div>${this.$route.fullPath}</div>`);
}, 2000);
},
mounted() {
console.log("mounted-" + new Date().getTime());
}
});
const router = new Router({
mode: "history",
routes: [{ path: "/random/:random", component: testComponent }]
});
/* eslint-disable no-new */
new Vue({
el: "#app",
router,
render: h => h(App)
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question