【问题标题】:How can I make title bar dynamic on vuetify?如何在 vuetify 上使标题栏动态化?
【发布时间】:2020-03-21 08:14:20
【问题描述】:

我看到 vuetify 项目有标题栏。但是 public/index.html 中的标题。 src 文件夹外

所以我很难让它动态化。每个页面必须有不同的标题。如果一样的话,对SEO的影响很大

我的 public/index.html 是这样的:

<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width,initial-scale=1.0">
    <link rel="icon" href="<%= BASE_URL %>favicon.ico">
    <title>test-vuetify</title>
    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@mdi/font@latest/css/materialdesignicons.min.css">
  </head>
  <body>
    <noscript>
      <strong>We're sorry but test-vuetify doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
    </noscript>
    <div id="app"></div>
    <!-- built files will be auto injected -->
  </body>
</html>

我该如何解决这个问题?我想让每一页的标题都不一样。根据页面内容

【问题讨论】:

  • 您从哪里获取页面内容?它是硬编码的还是从某个数据库中提取的?如果它来自某个数据库,您只需像设置正文数据一样设置标题数据
  • @EGC 数据库中存在数据,存在数据是硬编码的
  • 看起来你可以制作自己的组件来做到这一点:stackoverflow.com/questions/36612847/…
  • @Damian C 这种方法对 SEO 真的有用吗?如果我右键单击我的网站并选择View Page Source,我会看到标题、描述、关键字不会改变。我看起来怀疑这种方式是否正确

标签: html vue.js vue-component url-routing vuetify.js


【解决方案1】:

很难从问题中准确说出您的限制是什么,但如果这有助于其他人使他们的 Vuetify 标题栏动态...

index.js 中,向路由添加一些“元”:

import VueRouter from 'vue-router';

Vue.use(VueRouter);

const routes = [
  {
    path: '/page1',
    name: 'page-1',
    component: ...,
    meta: {
      title: 'Page 1'
    }
  },
  {
    path: '/page2',
    name: 'page-2',
    component: ...,
    meta: {
      title: 'Page 2'
    }
  }
]

const router = new VueRouter({
  mode: 'history',
  base: (your base url),
  routes: routes,
});

export default router

然后在 Vuetify 标题栏中,使用上面定义的路由元:

<v-toolbar-title>{{ $route.meta.title || "Default title" }}</v-toolbar-title>

【讨论】:

    猜你喜欢
    • 2020-07-09
    • 1970-01-01
    • 2020-07-14
    • 1970-01-01
    • 1970-01-01
    • 2020-04-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多