|
2 | 2 | <div> |
3 | 3 | <div class="container"> |
4 | 4 | <div class="row"> |
5 | | - <div class="col-md-8"> |
| 5 | + <div class="col-md-8" v-if="single_post"> |
6 | 6 | <h1>Edit Post:</h1> |
7 | 7 | <div class="form-group"> |
8 | 8 | <label>Title:</label> |
9 | | - <input v-model="title" class="form-control" type="text" placeholder="Enter the Title"> |
| 9 | + <input :value="single_post.title" @input="single_post.title = $event.target.value" class="form-control" type="text" placeholder="Enter the Title"> |
10 | 10 | </div> |
11 | 11 | <div class="form-group"> |
12 | 12 | <label>Category:</label> |
13 | | - <select v-model="category" class="custom-select" > |
| 13 | + <select :value="single_post.category" @input="single_post.category =$event.target.value" class="custom-select" > |
14 | 14 | <option v-for="category in categories" :value="category.id">{{category.category}}</option> |
15 | 15 | </select> |
16 | 16 | </div> |
17 | 17 | <div class="form-group"> |
18 | 18 | <label>Body:</label> |
19 | | - <markdown-editor v-model="body" ref="markdownEditor"></markdown-editor> |
| 19 | + <ckeditor :editor="editor" v-model="single_post.body" :config="editorConfig"></ckeditor> |
20 | 20 | </div> |
21 | 21 | <div class="form-group"> |
22 | | - <input @click="CreatePost" type="submit" class="btn btn-primary"> |
| 22 | + <input @click="UpdatePost" type="submit" class="btn btn-primary"> |
23 | 23 | </div> |
24 | 24 | </div> |
25 | 25 | </div> |
26 | 26 | </div> |
27 | 27 | </div> |
28 | 28 | </template> |
29 | 29 | <script type="text/javascript"> |
| 30 | +import { mapGetters } from 'vuex' |
| 31 | +import ClassicEditor from '@ckeditor/ckeditor5-build-classic'; |
30 | 32 | export default{ |
31 | 33 | data(){ |
32 | 34 | return{ |
33 | | - message: 'I am in', |
| 35 | + body:'', |
| 36 | + editor: ClassicEditor, |
| 37 | + editorConfig: { |
| 38 | + // The configuration of the editor. |
| 39 | + } |
| 40 | + } |
| 41 | + }, |
| 42 | + mounted(){ |
| 43 | + const slug = this.$route.params.slug; |
| 44 | + this.$store.dispatch('get_single_post',slug) |
| 45 | + this.$store.dispatch('get_Categories') |
| 46 | + }, |
| 47 | + computed:{ |
| 48 | + ...mapGetters([ |
| 49 | + 'single_post', |
| 50 | + 'categories' |
| 51 | + ]) |
| 52 | + }, |
| 53 | + methods:{ |
| 54 | + UpdatePost(){ |
| 55 | + console.log('update post'); |
| 56 | + const slug = this.$route.params.slug; |
| 57 | + const UpdateData = [this.single_post.title, this.single_post.category, this.single_post.body]; |
| 58 | + console.log(UpdateData); |
| 59 | +
|
| 60 | + this.$store.dispatch('Edit_Post',UpdateData,slug) |
34 | 61 | } |
35 | 62 | } |
36 | 63 | } |
|
0 commit comments