【问题标题】:Nuxt/Vue Route Params update Meta titleNuxt/Vue 路由参数更新元标题
【发布时间】:2020-09-11 18:05:18
【问题描述】:

所以我正在使用 Nuxt 和 Axios 通过 route.params.id 获取 JSON 数据,一切正常,但现在我需要将其中一些数据放入我的元标头中,但不知道该怎么做,请参阅下面的失败示例。

页面/帖子/_id/_slug.vue

<template>
  <div id="content" class="block float-left w-full pt-32">
    <div class="block text-black mx-auto my-0 w-10/12" v-for="post in getData($route.params.id)" :key="post.id">

        <!-- column 1 -->
        <main class="block float-left md:pr-16 w-full md:w-9/12">
          <h1 class="block float-left w-full text-black mb-8 uppercase title">
            <span class="leading-none font-extrabold text-xl md:text-3xl">{{post.loc}}</span><br/>
            <span class="leading-none font-bold text-2xl md:text-5xl">{{post.serv}}</span>
          </h1>
          <div class="content block float-left w-full" v-html="post.cont" />
        </main>
        <!-- column 1 -->

    </div>
  </div>
</template>

这很好用

import json from '~/static/mpc-data.json'
export default {

这就是问题所在

  head () {
    return {
      meta_title: post.loc + post.serv,
      meta: [
        { hid: 'title', name: 'title', content: this.meta_title },
        { hid: 'og:title', name: 'og:title', content: this.meta_title }
      ]
    }
  }

其余的 - 一切正常

  data () {
    return {
      posts: json,
      title: ''
    }
  },
  methods: {
    getData (id) {
      const data = this.posts
      return data.filter((item) => {
        return item.id === id
      })
    },
    getArea (loc) {
      const data = this.posts
      return data.filter((item) => {
        return item.loc === loc
      })
    }
  }
}

【问题讨论】:

    标签: vue.js axios nuxt.js meta-tags


    【解决方案1】:

    我认为不是meta_title,而是title。 更多参考:

    https://nuxtjs.org/api/pages-head/

    【讨论】:

      猜你喜欢
      • 2021-06-09
      • 1970-01-01
      • 2023-03-14
      • 2020-06-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-08
      • 1970-01-01
      相关资源
      最近更新 更多