Skip to content

Instantly share code, notes, and snippets.

@nabrown
Created July 27, 2018 22:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nabrown/1dcd5cca2abc0c20a65b1f5872cd91e4 to your computer and use it in GitHub Desktop.
Save nabrown/1dcd5cca2abc0c20a65b1f5872cd91e4 to your computer and use it in GitHub Desktop.
A functional component using a render function
export default {
functional: true,
props: {
src: {
required: true,
type: String
},
type: {
required: true,
type: String
},
tags: {
required: false,
type: Array
}
},
render(createElement, {props, listeners, slots}){
const img = createElement(
'img',
{
'attrs': {
'src': props.src
}
}
)
const caption = slots().default ? createElement(
'figcaption',
[ createElement('span', slots().default) ]
) : ''
const tags = props.tags && (props.type != 'framed') ? createElement(
'div',
{'class' : 'tags'},
props.tags.map(function (tag) {
return createElement('span', tag)
})
) : ''
return createElement(
'figure',
{
'class': props.type,
'on' : {
'click': listeners.click
}
},
[img, caption, tags]
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment