Last active
January 30, 2018 11:19
-
-
Save gearmobile/ec98e60eeeeabdaaf6dc464a9073935e to your computer and use it in GitHub Desktop.
PostsPage
This file contains hidden or 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 lang="pug"> | |
.container | |
.row | |
.col-xs-12 | |
h1 | |
| Posts | |
h3 | |
| This file will list all the posts | |
section.panel.panel-success( v-if="posts.length" ) | |
.panel-heading | |
| list of posts | |
table.table.table-striped | |
tr | |
th Title | |
th Description | |
th Action | |
tr( v-for="(post, index) in posts", :key="post.title" ) | |
td {{ post.title }} | |
td {{ post.description }} | |
section.panel.panel-danger( !v-if="posts.length" ) | |
p | |
| There are no posts ... Lets add one now! | |
div | |
router-link( :to="{ name: 'NewPost' }" ) | |
| add new post | |
</template> | |
<script> | |
import PostsService from '@/services/PostsService' | |
export default { | |
name: 'PostsPage', | |
data () { | |
return { | |
posts: [] | |
} | |
}, | |
methods: { | |
async getPosts () { | |
const response = await PostsService.fetchPosts() | |
this.posts = response.data.posts | |
} | |
}, | |
mounted () { | |
this.getPosts() | |
} | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment