html:

设置路由 router.js

 {
    path: '/',
    name: 'knowIndex',
    component: resolve => require(['@/views/knowPoint/index'], resolve),
    meta: {
      title: '知识点主页'
    },
    redirect: '/task',
    children: [
      {
        path: '/task',
        name: 'task',
        component: resolve => require(['@/views/knowPoint/task'], resolve),
        meta: {
          title: '知识点(数学)'
        }
      },
      {
        path: '/knowPhysics',
        name: 'knowPhysics',
        component: resolve => require(['@/views/knowPoint/knowPhysics'], resolve),
        meta: {
          title: '知识点(物理)'
        }
      }
    ]
  }

 js:

 在watch中加上事件监听:

 watch: {

    $route: {

      handler (val, oldval) {

        this.activeId = val.path.replace('/task', '/') // 当前活动路由

      },

      // 深度观察监听

      deep: true

    }

  }


      希望我的愚见能够帮助你哦~,若有不足之处,还望指出,你们有更好的解决方法,欢迎大家在评论区下方留言支持,大家一起相互学习参考呀~

Logo

前往低代码交流专区

更多推荐