Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

请教一下怎么在每个页面给 NavBar 分别设置 title? #45

Closed
magic3584 opened this issue Dec 12, 2023 · 4 comments
Closed

请教一下怎么在每个页面给 NavBar 分别设置 title? #45

magic3584 opened this issue Dec 12, 2023 · 4 comments

Comments

@magic3584
Copy link

插槽看了还是不太懂,NavBar 和 每个 component 也没有嵌套关系

      <van-nav-bar
        fixed
        placeholder
        left-arrow
        safe-area-inset-top
        @click-left="onClickLeft"
      >
        <template #title="slotProps">
          {{ slotProps }}
        </template>
      </van-nav-bar>

      <router-view v-slot="{ Component }">
        <keep-alive :include="cachedViews">
          <component :is="Component" />
        </keep-alive>
      </router-view>
@yulimchen
Copy link
Owner

可以尝试 NavBar title 属性绑定路由的 meta.title 值

@magic3584
Copy link
Author

magic3584 commented Dec 12, 2023

        <template #title>
          11 {{ router.currentRoute.name }}
        </template>

WX20231212-182607

很奇怪 router.currentRoute 能出现一大串,加上 name 就无了。。。可是明明有值

@yulimchen
Copy link
Owner

yulimchen commented Dec 12, 2023

const title = computed(() => {
  const route = router.currentRoute.value;
  return route.meta.title;
});

<template #title> {{ title }} </template>

@magic3584
Copy link
Author

原来是个 ref...
感谢大佬!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants