【发布时间】:2022-01-28 18:23:03
【问题描述】:
我想问一下渲染默认子视图的问题。
我知道 topic 存在类似的问题,但我很确定它适用于 VUE2 和较旧的 vue-router。我在呈现视图类别的默认子项时遇到问题。当我去<router-link :to="{ name: routeName, params: { category: item.id } }
除了<router-view /> 它是空的,一切都可以渲染...
我想出了一个使用 beforeUpdate(),beforeCreate() 的解决方案,但这似乎是在重新发明轮子。 如果我转到 /category/{id} 然后转到 /category/{id}/room/{id} 并返回一页,将呈现默认视图
进入/category/{id}后如何让默认子加载?
router.js
{
path: '/category/:category',
name: 'Category',
props: true,
component: Category,
children: [
{
path: '',
name: 'FavouriteDevicesInCategory',
component: Devices,
props: true,
},
{
path: 'room/:room',
name: 'Devices',
component: Devices,
props: true,
},
],
},
Category.vue - 查看
<template>
<div class="control">
<div class="left">
[...]
</div>
<div class="right">
<router-view />
</div>
</div>
</template>
<script>
export default {
props: ['category', 'room'],
/** generate default router-view */
beforeUpdate() {
this.$router.push('');
},
beforeCreate() {
this.$router.push('');
},
};
【问题讨论】:
标签: javascript vue.js vue-router vuejs3