Skip to content

Instantly share code, notes, and snippets.

@gearmobile
Last active January 30, 2018 11:19
Show Gist options
  • Save gearmobile/ec98e60eeeeabdaaf6dc464a9073935e to your computer and use it in GitHub Desktop.
Save gearmobile/ec98e60eeeeabdaaf6dc464a9073935e to your computer and use it in GitHub Desktop.
PostsPage
<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