From 2f6c27b750928cf8c5016dca9cfcd26639b26c15 Mon Sep 17 00:00:00 2001 From: Declan de Wet Date: Sun, 6 Nov 2016 21:59:12 +0200 Subject: [PATCH] add basic render example + fix a bug where missing root metInfo prevented fetching metaInfo from deeper in the component heirarchy --- examples/basic-render/app.js | 27 +++++++++++++++++++++++++++ examples/basic-render/index.html | 5 +++++ examples/index.html | 1 + src/shared/getComponentOption.js | 29 ++++++++++++++--------------- 4 files changed, 47 insertions(+), 15 deletions(-) create mode 100644 examples/basic-render/app.js create mode 100644 examples/basic-render/index.html diff --git a/examples/basic-render/app.js b/examples/basic-render/app.js new file mode 100644 index 0000000..8b5737c --- /dev/null +++ b/examples/basic-render/app.js @@ -0,0 +1,27 @@ +import Vue from 'vue' +import VueMeta from 'vue-meta' + +Vue.use(VueMeta) + +Vue.component('child', { + name: 'Child', + props: ['page'], + render (h) { + return h('h3', null, this.page) + }, + metaInfo: { + title () { + return this.page + } + } +}) + +new Vue({ + template: ` +
+

Basic Render

+

Inspect Element to see the meta info

+ +
+ ` +}).$mount('#app') diff --git a/examples/basic-render/index.html b/examples/basic-render/index.html new file mode 100644 index 0000000..c4c535e --- /dev/null +++ b/examples/basic-render/index.html @@ -0,0 +1,5 @@ + + +← Examples index +
+ diff --git a/examples/index.html b/examples/index.html index c752153..9e6aa69 100644 --- a/examples/index.html +++ b/examples/index.html @@ -8,6 +8,7 @@

Vue Meta Examples

diff --git a/src/shared/getComponentOption.js b/src/shared/getComponentOption.js index f5cb403..a816082 100644 --- a/src/shared/getComponentOption.js +++ b/src/shared/getComponentOption.js @@ -34,22 +34,21 @@ export default function getComponentOption (opts, result = {}) { clone: true, arrayMerge }) - - // collect & aggregate child options if deep = true - if (deep && component.$children.length) { - component.$children.forEach((childComponent) => { - result = getComponentOption({ - component: childComponent, - option, - deep, - arrayMerge - }, result) - }) - } - - return result + } else { + result = data } - result = data + } + + // collect & aggregate child options if deep = true + if (deep && component.$children.length) { + component.$children.forEach((childComponent) => { + result = getComponentOption({ + component: childComponent, + option, + deep, + arrayMerge + }, result) + }) } return result