Skip to content

Instantly share code, notes, and snippets.

@augustogoulart
Created May 26, 2018 04:06
Show Gist options
  • Save augustogoulart/334881a3b1cf18ecb764fb57fae2d0f3 to your computer and use it in GitHub Desktop.
Save augustogoulart/334881a3b1cf18ecb764fb57fae2d0f3 to your computer and use it in GitHub Desktop.
<template>
<nuxt-link class="post-preview" :to="postLink">
<article>
<div class="post-thumbnail"
:style="{backgroundImage: `url(${thumbnail})`}"></div>
<div class="post-content">
<h1>{{ title }}</h1>
<p>{{ previewText }}</p>
</div>
</article>
</nuxt-link>
</template>
<script>
export default {
name: 'PostPreview',
props: {
id: {
type: String,
required: true
},
isAdmin: {
type: Boolean,
required: true
},
title: {
type: String,
required: true
},
previewText: {
type: String,
required: true
},
thumbnail: {
type: String,
required: true
}
},
computed: {
postLink() {
return this.isAdmin ? `/admin/${this.id}` : `/posts/${this.id}`
}
}
}
</script>
<style scoped>
.post-preview {
border: 1px solid #ccc;
box-shadow: 0 2px 2px #ccc;
background-color: white;
width: 90%;
}
a {
text-decoration: none;
color: black;
}
@media (min-width: 850px) {
.post-preview {
width: 400px;
margin: 10px;
}
}
.post-thumbnail {
width: 100%;
height: 200px;
background-position: center;
background-size: cover;
}
.post-content {
padding: 10px;
text-align: center;
}
a:hover .post-content,
a:active .post-content {
background-color: #ccc;
}
</style>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment