尝试创建面包屑,通过获取URL的完整路径并在数组中拆分,然后循环通过该数组来呈现一些面包屑。
问题是crumbs
在路由改变时不会得到更新,我如何使它工作?
export default defineComponent({
setup() {
const store = useThemeStore();
const { fullPath } = useRoute();
return {
changeThemeStore: computed(() => store.changeTheme),
currentTheme: store.getCurrentTheme === "dark",
crumbs: computed(() => fullPath.substring(1, fullPath.length).split('/'))
};
},
methods: {
changeTheme() {
this.changeThemeStore();
},
goToRoute(crumb: string) {
this.$router.push('/' + crumb)
}
},
1条答案
按热度按时间i5desfxk1#
尽量不破坏当前路由,直接使用它,似乎被破坏的对象失去了React性: