浏览器标题

虽然是单页面应用,但是很多情况下,我们需要动态改变浏览器的 title 信息。通过在路由的 meta 属性设置 title 可以很方便的完成这个需求。

{
    path: '/',
    component: Index,
    meta: {
        title(to, from) {
            return '首页';
        },
        // or title: '首页',
    },
}

具体实现是,倒序遍历匹配到的路由信息,发现有 title 信息则停止遍历,所以多个子页面有同一个 title,只需要在父页面设置其 title 即可。