paramander / contentful-rich-text-vue-renderer

Render Contentful Rich Text field using Vue
https://www.npmjs.com/package/contentful-rich-text-vue-renderer
MIT License
38 stars 12 forks source link

Passing props to custom element #15

Closed damienroche closed 4 years ago

damienroche commented 4 years ago

Hi, I would like to display EMBEDDED_ASSET, within the Contenful Deliver API I can only get the asset id. So I have to load a custom component like this :

[BLOCKS.EMBEDDED_ASSET]: (node, key, h, next) => {
      return h('contentful-asset', { key, id: node.data.target.sys.id })
    }

On my ContenfulAssset component I will make a request to retrieve asset url. But the prop doesn't seems to be passed to the custom component.

I used the same syntax of your documentation

return h('Link', { key: key, to: 'link to embedded entry' }, 'content for the component');

tolgap commented 4 years ago

Hi Damien,

I assume you are trying to pass in the id prop. If you're trying to use the h method, this is also called createElement in Vue: https://vuejs.org/v2/guide/render-function.html#createElement-Arguments .

bilelz commented 4 years ago

Hello, @damienroche, you can write this:

[BLOCKS.EMBEDDED_ASSET]: (node, key, h, next) => {
  return h('contentful-asset', {
    key,
    props: { id: node.data.target.sys.id },
  });
},
damienroche commented 4 years ago

thanks @bilelz

tolgap commented 4 years ago

I'll close this issue as the example should fix it.