Special cases

Read first

Understanding How is metaInfo resolved? is probably a prerequisite for these cases

Remove parent property by child

If a child returns null as content value then the parent metaInfo property with the same vmid will be ignored

Content value

With content value we mean the following value of a metaInfo property:

  • the value of a key for object types as htmlAttrs
  • the value of [contentKeyName] or innerHTML keys for collection types as meta

The following might be a bit far-fetched, but its just an example

  1. // parent
  2. metaInfo: {
  3. style: [{
  4. vmid: 'page-load-overlay',
  5. innerHTML: `
  6. body div.loading {
  7. z-index: 999;
  8. background-color: #0f0f0f;
  9. opacity: 0.9;
  10. }
  11. `,
  12. }]
  13. }
  14. // dynamically loaded child
  15. metaInfo() {
  16. const style = this.cssTexts
  17. return { style }
  18. },
  19. data() {
  20. return {
  21. this.cssTexts: []
  22. }
  23. },
  24. mounted() {
  25. this.cssTexts.push({
  26. vmid: 'page-load-overlay',
  27. innerHTML: null
  28. })
  29. }

Use child property conditionally

If you wish to use a child property conditionally and use the parents' property as default value, make sure the child returns undefined as content value

Content value

With content value we mean the following value of a metaInfo property:

  • the value of a key for object types as htmlAttrs
  • the value of [contentKeyName] or innerHTML keys for collection types as meta

The below example will still show a description when the GET in the child fails

  1. // parent
  2. metaInfo: {
  3. meta: [{
  4. vmid: 'description',
  5. name: 'description',
  6. content: 'my standard description',
  7. }]
  8. }
  9. // child
  10. metaInfo() {
  11. return {
  12. meta: [{
  13. vmid: 'description',
  14. name: 'description',
  15. content: this.description,
  16. }]
  17. }
  18. },
  19. data() {
  20. return {
  21. description: undefined
  22. }
  23. },
  24. methods: {
  25. getDescription() {
  26. this.description = this.$axios.get()
  27. if (!this.description) {
  28. // if GET request failed or returned empty,
  29. // explicitly set to undefined so the parents'
  30. // default description is used
  31. this.description = undefined
  32. }
  33. }
  34. }

Boolean attributes

vue-meta maintains a listSpecial cases - 图1 of attributes which are Boolean attributes according to the HTML specs (and some extra). Whatever value you will pass to these attributes, they will be rendered as a Boolean attribute.*

*Except for the special values undefined and null, see above

Note

Prior to v2.0 any attribute key with undefined as value was rendered as Boolean attribute. This has been removed as bundlers often remove object properties with an undefined value as given a = {} then a.a === undefined