相关疑难解决方法(0)

Vue-router 正在更改 url 但不会重新渲染组件

首先,我检查并打开历史模式,我vue-router像这样调用:

const router = new Router({
  mode: 'history',
  base: process.env.BASE_URL,
  routes: routes,
});
Run Code Online (Sandbox Code Playgroud)

我当前所在的路线是/page/item/8,并且我正在重定向到/page/item/9。目前,网址已更改,但页面不会重新呈现,使我保持之前的相同视图。

这个重定向是这样完成的:

this.$router.push({ name: 'PageItem', params: { itemId: '9' }}).catch(err => {
  // Stop Vue.router throwing an error if a user clicks on a notification with the same route.
  if (err.name !== 'NavigationDuplicated') {
    this.$logger.debug.log(err);
  }
});
Run Code Online (Sandbox Code Playgroud)

有问题的路线如下:

import PageWrapper from '@/layouts/PageWrapper';
    
export default [
  {
    path: '/page',
    name: 'page',
    component: PageWrapper,
    children: [
      ... Other Routes ...
      {
        component: () …
Run Code Online (Sandbox Code Playgroud)

vue.js vue-router

9
推荐指数
1
解决办法
9726
查看次数

vue-router始终创建一个新的Component实例

我在vue-router中发现了一个问题,它引发了我很多.总是当我在我的路线之间切换时,会创建一个新的组件实例.此外,旧实例不会被删除并在后台运行!

我希望当我打开一条路线时,旧组件将被销毁或停止运行.

有解决方法来解决这个问题吗?

这是一个小提琴:https://jsfiddle.net/4xfa2f19/5885/

let foo = {
    template: '<div>Foo</div>',
    mounted() {
        console.log('Mount Foo with uid: ' + this._uid);
        setInterval(() => {console.log('Instance ' + this._uid + ' of Foo is running')}, 500);
    }
};

let bar = {
    template: '<div>Bar</div>',
    mounted() {
        console.log('Mount Bar with uid: ' + this._uid);
        setInterval(() => {console.log('Instance ' + this._uid + ' of Bar is running')}, 500);
    }
};


const router = new VueRouter({
    routes: [
        { path: '/user/foo', component: foo }, …
Run Code Online (Sandbox Code Playgroud)

javascript routing vue.js vue-router

3
推荐指数
1
解决办法
3142
查看次数

标签 统计

vue-router ×2

vue.js ×2

javascript ×1

routing ×1