如何在metaInfo-Vue Spa中创建动力学元标记?

时间:2019-07-24 09:59:34

标签: vue.js meta-tags

我应该使用条件来创建动态元标记,但不知道该怎么做!我在Google中搜索,但没有得到任何结果

我尝试在metaInfo中使用一种方法,但没有用

1 个答案:

答案 0 :(得分:0)

您可以尝试vue-head模块。

安装:

npm install vue-head --save

导入:

import Vue from 'vue'
import VueRouter from 'vue-router'
import VueHead from 'vue-head'

Vue.use(VueHead)
Vue.use(VueRouter)
...

示例:

export default {
  data: function () {
    return {
      title: 'My Title'
    }
  },
  // Usage with context the component
  head: {
    // To use "this" in the component, it is necessary to return the object through a function
    title: function () {
      return {
        inner: this.title
      }
    },
    meta: [
      { name: 'description', content: 'My description', id: 'desc' }
    ]
  }
    ...
  }
}