Created
January 31, 2018 17:26
-
-
Save gearmobile/79bb664b5b50a62896425f9e44b3be04 to your computer and use it in GitHub Desktop.
PostsPage.vue
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 | |
div | |
router-link( :to="{ name: 'NewPost' }" ) | |
| add new post | |
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="index" ) | |
td {{ post.title }} | |
td {{ post.description }} | |
td | |
router-link( :to="{ name: 'EditPost', params: { id: post._id } }" ) | |
| edit post | |
button.btn.btn-danger.btn-sm( type="button", @click="removePost(post._id)" ) | |
| delete | |
section.panel.panel-danger( v-else ) | |
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 | |
}, | |
async removePost (value) { | |
await PostsService.deletePost(value) | |
this.getPosts() | |
} | |
}, | |
mounted () { | |
this.getPosts() | |
} | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment