vuejs无法更新组件

时间:2019-03-31 11:14:00

标签: javascript vue.js

当我单击链接时,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'
});

1 个答案:

答案 0 :(得分:0)

您的所有路线的组件都相同,因此Vue仅加载testComponent一次。一旦加载了组件,Vue将永远不会再次重新加载它。