当我单击链接时,mounted()
有效,但是新模板未从服务器加载,如果更改了路线,vue将不会发送AJAX请求。
<section class="content">
<router-view :key="$route.fullPath"></router-view>
</section>
<router-link to="/foo"></router-link>
<router-link to="/bar"></router-link>
<router-link to="/somelink"></router-link>
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'
});
答案 0 :(得分:0)
您的所有路线的组件都相同,因此Vue仅加载testComponent
一次。一旦加载了组件,Vue将永远不会再次重新加载它。