2
0
mirror of https://github.com/tenrok/vue-meta.git synced 2026-05-18 06:29:37 +03:00
Files
vue-meta/docs/faq/component-props.md
T
2019-03-10 21:58:13 +01:00

913 B

How to use component props or data

Easy. Instead of defining metaInfo as an object, define it as a function and access this as usual:

Post.vue:

<template>
  <div>
    <h1>{{{ title }}}</h1>
  </div>
</template>

<script>
  export default {
    name: 'post',
    props: ['title'],
    data () {
      return {
        description: 'A blog post about some stuff'
      }
    },
    metaInfo () {
      return {
        title: this.title,
        meta: [
          { vmid: 'description', name: 'description', content: this.description }
        ]
      }
    }
  }
</script>

PostContainer.vue:

<template>
  <div>
    <post :title="title"></post>
  </div>
</template>

<script>
  import Post from './Post.vue'

  export default {
    name: 'post-container',
    components: { Post },
    data () {
      return {
        title: 'Example blog post'
      }
    }
  }
</script>