美文网首页
vue3 监听路由变化

vue3 监听路由变化

作者: 冰落寞成 | 来源:发表于2023-03-14 14:56 被阅读0次
    watch(() => router.currentRoute.value.path, (toPath) => {
      checkCurrentRoute(toPath)
    })
    const checkCurrentRoute = (current) => {
      for (const item of menus.value) {
        if (item.path === current) {
          activeRoute.value = item.path
        } else if (item.children) {
          const subitem = item.children.find(v => v.path === current)
          if (subitem) {
            activeRoute.value = item.subview ? item.path : current
          }
        } else {
          activeRoute.value = current
        }
      }
    }
    

    相关文章

      网友评论

          本文标题:vue3 监听路由变化

          本文链接:https://www.haomeiwen.com/subject/xktkrdtx.html