Created
June 23, 2018 22:02
-
-
Save kevinbreaker/f6cd8afde918bce6d43eabca389cdcde to your computer and use it in GitHub Desktop.
Primeiros contatos com render functions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<div id="app"> | |
<card :src="link" title="um titulo legal" :size="tamanho" msg="Bem vindo a um componente que utiliza render function"/> | |
</div> | |
</template> | |
<script> | |
import Card from './components/Card.vue' | |
export default { | |
name: 'app', | |
data: () => ({ | |
link: 'http://www.freepngimg.com/download/skull/20813-8-skull-photos.png', | |
tamanho: { | |
width: 'calc(100vw / 2)', | |
// height: 'calc(100vh / 4)' | |
} | |
}), | |
components: { | |
Card | |
} | |
} | |
</script> | |
<style> | |
#app { | |
font-family: 'Avenir', Helvetica, Arial, sans-serif; | |
-webkit-font-smoothing: antialiased; | |
-moz-osx-font-smoothing: grayscale; | |
text-align: center; | |
color: #2c3e50; | |
margin-top: 60px; | |
} | |
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
export default { | |
props: { | |
msg: String, | |
backgroundColor: { | |
type: String, | |
default: '#a3a3a3' | |
}, | |
size: { | |
type: [Number, String, Object], | |
default: function () { | |
return { | |
width: 100, | |
height: '200px' | |
} | |
}, | |
}, | |
src: String, | |
title: String | |
}, | |
methods: { | |
clicked () { | |
alert('Fui clickado ') | |
} | |
}, | |
render (h) { | |
console.log(this.src) | |
const figure = () => { | |
if (this.src) { | |
return h('figure', {}, [ | |
h('img', { | |
domProps: { | |
src: this.src | |
} | |
}) | |
]) | |
} | |
} | |
return h('div', { | |
style: { | |
background: this.backgroundColor, | |
height: this.size.height || 'auto', | |
width: this.size.width || '100%', | |
borderRadius: '7px' | |
}, | |
attrs: { | |
id: 'card' | |
} | |
}, [ | |
// TIPO: Componente de titulo | |
h('header', {}, [ | |
h('h1', { | |
attrs: { | |
id: 'title' | |
} | |
}, this.title) | |
]), | |
// TIPO: Componente de corpo | |
h('main', { | |
attrs: { | |
id: 'body-card' | |
} | |
}, [ | |
h('p', { | |
attrs: { | |
id: 'text-content' | |
} | |
}, this.msg), | |
figure() | |
]), | |
// TIPO: componente de ação | |
h('footer', { | |
attrs: { | |
id: 'footer-card' | |
} | |
}, [ | |
h('nav', { | |
attrs: { | |
id: 'nav-card' | |
} | |
}, [ | |
h('button', { | |
attrs: { | |
id: 'button-card' | |
}, | |
on: { | |
click: this.clicked | |
}, | |
domProps: { | |
textContent: 'enviar' | |
} | |
}, []) | |
]) | |
]) | |
]) | |
} | |
} | |
</script> | |
<style> | |
img { | |
height: 50px; | |
width: 50px; | |
} | |
#card { | |
margin: 5px; | |
} | |
#title { | |
font-family: fantasy; | |
font-size: 24px; | |
text-transform: uppercase; | |
padding: 10px 5px | |
} | |
#body-card { | |
padding: 0 5px; | |
} | |
#text-content { | |
padding: 0 5px; | |
} | |
#footer-card { | |
padding: 5px 2px; | |
margin-top: 5px; | |
} | |
#nav-card { | |
display: flex; | |
justify-content: flex-end; | |
padding: 5px; | |
margin-right: 10px; | |
} | |
#button-card { | |
outline: none; | |
border: none; | |
border-radius: 3px; | |
background: teal; | |
color: white; | |
padding: 5px; | |
} | |
</style> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment