Skip to content

Instantly share code, notes, and snippets.

@gearmobile
Created January 31, 2018 17:24
Show Gist options
  • Save gearmobile/3a8b19429152a34cbf075bc8a8e925f2 to your computer and use it in GitHub Desktop.
Save gearmobile/3a8b19429152a34cbf075bc8a8e925f2 to your computer and use it in GitHub Desktop.
EditPostPage.vue
<template lang="pug">
section.edit
h1
| edit post
form( @submit.prevent="editPost()" )
div
input( type="text", name="title", id="title", placeholder="Title", v-model.trim="post.title" )
div
input( type="text", name="description", id="description", placeholder="Description", v-model.trim="post.description" )
div
button( type="submit", name="editPost" )
| edit post
div
router-link( :to="{ name: 'Posts' }" )
| go to list of posts
</template>
<script>
import PostsService from '@/services/PostsService'
export default {
name: 'EditPostPage',
data () {
return {
post: {
title: '',
description: ''
}
}
},
methods: {
async getPost () {
const response = await PostsService.getPost({ id: this.$route.params.id })
this.post.title = response.data.title
this.post.description = response.data.description
},
async editPost () {
if (this.post.title !== '' && this.post.description !== '') {
await PostsService.updatePost({
id: this.$route.params.id,
title: this.post.title,
description: this.post.description
})
this.$router.push({ name: 'Posts' })
}
}
},
mounted () {
this.getPost()
}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment