使用nuxt,如何将路线名称放在页面标题中?

JavaScript Vue.js

小宇宙番长

2020-03-26

我想为每个页面将页面标题设置为不同的值。

在常规的Vue.js中,我执行了以下操作:

import router from './router'
import { store } from './store/store';

router.beforeEach((to, from, next) => {
    store.mutations.setRoute(to);
    document.title = store.getters.pageTitle;
    next();
}

我如何在nuxt中获得这种效果?

也就是说,在初始页面加载和更改页面时,我都希望浏览器选项卡的标题更改。例如,从“我的应用程序-关于”到“我的应用程序-个人资料”。

第3750篇《使用nuxt,如何将路线名称放在页面标题中?》来自Winter(https://github.com/aiyld/aiyld.github.io)的站点

1个回答
小哥斯丁 2020.03.26

nuxt docs中pages您可以在每个组件中定义head函数,该函数返回页面标题,即

head() {
    return {
      title: "About page"
    };
  }

问题类别

JavaScript Ckeditor Python Webpack TypeScript Vue.js React.js ExpressJS KoaJS CSS Node.js HTML Django 单元测试 PHP Asp.net jQuery Bootstrap IOS Android