|
75 | 75 | - [Performance](#performance)
|
76 | 76 | - [How to prevent the update on the initial page render](#how-to-prevent-the-update-on-the-initial-page-render)
|
77 | 77 | - [FAQ](#faq)
|
78 |
| - - [How do I use component data in `metaInfo`?](#how-do-i-use-component-data-in-metainfo) |
79 |
| - - [How do I use component props in `metaInfo`?](#how-do-i-use-component-props-in-metainfo) |
| 78 | + - [How do I use component props and/or component data in `metaInfo`?](#how-do-i-use-component-props-andor-component-data-in-metainfo) |
80 | 79 | - [How do I populate `metaInfo` from the result of an asynchronous action?](#how-do-i-populate-metainfo-from-the-result-of-an-asynchronous-action)
|
81 | 80 | - [Examples](#examples)
|
82 | 81 |
|
@@ -610,71 +609,56 @@ Add the `data-vue-meta-server-rendered` attribute to the `<html>` tag on the ser
|
610 | 609 |
|
611 | 610 | Here are some answers to some frequently asked questions.
|
612 | 611 |
|
613 |
| -## How do I use component data in `metaInfo`? |
614 |
| -Specify a function instead of an object. It will need to return the same type as its definition. |
| 612 | +## How do I use component props and/or component data in `metaInfo`? |
615 | 613 |
|
616 |
| -**BlogPost.vue:** |
| 614 | +Easy. Instead of defining `metaInfo` as an object, define it as a function and access `this` as usual: |
| 615 | + |
| 616 | +**Post.vue:** |
617 | 617 | ```html
|
618 | 618 | <template>
|
619 |
| - <div id="page"> |
| 619 | + <div> |
620 | 620 | <h1>{{ title }}</h1>
|
621 | 621 | </div>
|
622 | 622 | </template>
|
623 | 623 |
|
624 | 624 | <script>
|
625 | 625 | export default {
|
626 |
| - name: 'BlogPost', |
627 |
| - data: () => ({ |
628 |
| - title: 'Sample blog post' |
629 |
| - }), |
630 |
| - metaInfo: { |
631 |
| - title () { |
632 |
| - return this.title |
| 626 | + name: 'post', |
| 627 | + props: ['title'], |
| 628 | + data () { |
| 629 | + return { |
| 630 | + description: 'A blog post about some stuff' |
| 631 | + } |
| 632 | + }, |
| 633 | + metaInfo () |
| 634 | + return { |
| 635 | + title: this.title, |
| 636 | + meta: [ |
| 637 | + { vmid: 'description', name: 'description', content: this.description } |
| 638 | + ] |
633 | 639 | }
|
634 | 640 | }
|
635 | 641 | }
|
636 | 642 | </script>
|
637 | 643 | ```
|
638 | 644 |
|
639 |
| -## How do I use component props in `metaInfo`? |
640 |
| -The same way you use data - specify a function instead of an object. It will need to return the same type as its definition. |
641 |
| - |
642 |
| -**BlogPostWrapper.vue** |
| 645 | +**PostContainer.vue:** |
643 | 646 | ```html
|
644 | 647 | <template>
|
645 |
| - <div id="page"> |
646 |
| - <blog-post :title="title"></blog-post> |
| 648 | + <div> |
| 649 | + <post :title="title"></post> |
647 | 650 | </div>
|
648 | 651 | </template>
|
649 | 652 |
|
650 | 653 | <script>
|
651 |
| - import BlogPost from './BlogPost.vue' |
| 654 | + import Post from './Post.vue' |
652 | 655 |
|
653 | 656 | export default {
|
654 |
| - name: 'BlogPostWrapper', |
655 |
| - components: { BlogPost }, |
656 |
| - data: () => ({ |
657 |
| - title: 'Example blog post' |
658 |
| - }) |
659 |
| - } |
660 |
| -</script> |
661 |
| -``` |
662 |
| - |
663 |
| -**BlogPost.vue** |
664 |
| -```html |
665 |
| -<template> |
666 |
| - <div id="page"> |
667 |
| - <h1>{{ title }}</h1> |
668 |
| - </div> |
669 |
| -</template> |
670 |
| - |
671 |
| -<script> |
672 |
| - export default { |
673 |
| - name: 'BlogPost', |
674 |
| - props: ['title'], |
675 |
| - metaInfo: { |
676 |
| - title () { |
677 |
| - return this.title |
| 657 | + name: 'post-container', |
| 658 | + components: { Post }, |
| 659 | + data () { |
| 660 | + return { |
| 661 | + title: 'Example blog post' |
678 | 662 | }
|
679 | 663 | }
|
680 | 664 | }
|
|
0 commit comments