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

如何动态切换tab标题 #256

Closed
dodu2014 opened this issue Jun 26, 2023 · 5 comments
Closed

如何动态切换tab标题 #256

dodu2014 opened this issue Jun 26, 2023 · 5 comments

Comments

@dodu2014
Copy link
Contributor

dodu2014 commented Jun 26, 2023

很感谢 soybean-admin,模块思路都很清晰,已经尝试在使用了。现在出现了一个小问题,请教下作者。

需求是这样的:
有些页面组件是新增和编辑都可以同时使用同一页面组件的,由于当前走的文件路由,路由name和path的枚举都已经自动生成,所以不好自定义,想在想在进入改页面时,在 onMounted 通过 route 的 query 来判断是否是那种操作,来通过改变 route.meta 来动态更新 tab 的标题 和 页面标题显示,示例:

import { onMounted } from 'vue';
import { useRoute } from 'vue-router';

const route = useRoute();

onMounted(() => {
  route.meta.title = route.query.id ? '编辑资讯' : '新增资讯';
  route.meta.i18nTitle = route.query.id
    ? 'message.routes.articles.article_edit'
    : 'message.routes.articles.article_new';
});

可是并不能通过该方法得到想要的结果。

也尝试使用 useTabStore().setActiveTabTitle(title) 来更新,结果也不是想要的(这个貌似不起任何作用)。

@dodu2014
Copy link
Contributor Author

这只是一种情况,可能还有很多情况都是不同的路由,指向的页面组件是同一个。这个时候改怎么处理tab标题和页面标题呢

@honghuangdc
Copy link
Member

这只是一种情况,可能还有很多情况都是不同的路由,指向的页面组件是同一个。这个时候改怎么处理tab标题和页面标题呢

推荐用这种方式,将页面内容抽离出一个组件,然后分别引入到编辑和新增的页面。
至于区分编辑还是新增,可以在路由的props给个属性区分

@dodu2014
Copy link
Contributor Author

谢谢,我也这样考虑过,并且需要多个路由指向的view,感觉有些麻烦。
另外在示例:功能/tab页签 下使用 setActiveTabTitle 设置当前tab标题也是无效。可能是个bug吧,能否修复。

@honghuangdc
Copy link
Member

谢谢,我也这样考虑过,并且需要多个路由指向的view,感觉有些麻烦。
另外在示例:功能/tab页签 下使用 setActiveTabTitle 设置当前tab标题也是无效。可能是个bug吧,能否修复。

之前上了国际化的功能,所以Tab这里优先用了国际化的文本,所以设置Tab标题的不起作用了

@dodu2014
Copy link
Contributor Author

好的,明白了,非常感谢~~

zyt520ham pushed a commit to zyt520ham/soybean-admin that referenced this issue Jul 28, 2023
* main: (103 commits)
  perf(hooks): perf useHookTable
  feat(hooks): add useHookTable
  fix(projects): correct the lang file name & add recommend vscode plugin i18n-ally
  feat(projects): new i18n function $t & login page and setting drawer config i18n
  chore(projects): correct the word spell
  chore(projects): update VSCode setting
  chore(projects): update pnpm-lock.yaml
  chore(deps): update deps
  fix(styles): 用户管理页面布局自适应屏幕高度 (fixed soybeanjs#253)
  feat(auth): 防止多次刷新token
  chore(projects): update deps & fix eslint code
  chore(projects): update package.json
  chore(deps): update deps
  docs(projects): update README.md logo
  chore(projects): update deps and fix swiper
  refactor(projects): 生产环境缓存主题变更为sessionStorage
  style(projects): update default theme color
  fix(projects): fix set tab title (fixed soybeanjs#256)
  chore(deps): update deps
  chore(deps): update deps
  ...

# Conflicts:
#	.env
#	build/plugins/index.ts
#	src/views/component/card/index.vue
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