Skip to content

Commit 224f90c

Browse files
committed
create article with tags and category is ok
1 parent 61c9cc0 commit 224f90c

File tree

4 files changed

+66
-16
lines changed

4 files changed

+66
-16
lines changed

src/api/article.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ export function fetchArticleList(queryParams) {
88
})
99
}
1010

11-
export function getArticleDetail(articleId) {
11+
export function getArticleDetail(articleId, queryParams) {
1212
return request({
1313
url: '/article/detail/' + articleId + '/',
1414
method: 'get',
15+
params: queryParams
1516
})
1617
}
1718

src/router/index.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {createRouter,createWebHistory} from 'vue-router'
33
import ArticleList from "../views/article/list";
44
import ArticleCreate from "../views/article/create";
55
import ArticleDetail from "../views/article/detail";
6+
import ArticleEdit from "../views/article/edit";
67
import LayOut from '../layout/index'
78
const routes = [
89
{
@@ -26,6 +27,12 @@ const routes = [
2627
component: ArticleDetail,
2728
name:'article detail'
2829

30+
},
31+
{
32+
path: 'edit/:id(\\d+)/',
33+
component: ArticleEdit,
34+
name:'article edit'
35+
2936
},
3037
{
3138
path: 'create',

src/views/article/create.vue

Lines changed: 42 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,31 @@
2222
</el-form-item>
2323
</div>
2424
</el-form>
25-
25+
<el-radio-group v-model="postForm.category">
26+
<el-radio-button label="1">python</el-radio-button>
27+
<el-radio-button label="2">vue</el-radio-button>
28+
<el-radio-button label="3">django</el-radio-button>
29+
<el-radio-button label="4">linux</el-radio-button>
30+
</el-radio-group>
31+
<el-select
32+
v-model="postForm.tags"
33+
placeholder="Select"
34+
:reserve-keyword="false"
35+
multiple
36+
filterable
37+
default-first-option
38+
allow-create
39+
size="small">
40+
<el-option
41+
v-for="tagname in tags"
42+
:key="tagname"
43+
:label="tagname"
44+
:value="tagname"
45+
/>
46+
</el-select>
2647
<sticky-nav
27-
:z-index="1800"
2848
:class-name="'sub-navbar '+postForm.status"
29-
style="padding: 0px 45px 20px 50px;margin-bottom: 30px;"
49+
style="padding: 0px 45px 15px 45px;"
3050
>
3151
<el-button v-loading="loading" style="margin-left: 10px;" type="success" @click="submitForm">
3252
Submit
@@ -61,7 +81,7 @@
6181
// }
6282
6383
export default {
64-
name: 'ArticleDetail',
84+
name: 'CreateArticle',
6585
components: {
6686
// Tinymce,
6787
// Upload,
@@ -96,7 +116,10 @@
96116
status: 'draft',
97117
title: '', // 文章题目
98118
content: '', // 文章内容
99-
importance: 1
119+
importance: 1,
120+
category:'',
121+
tags:[]
122+
100123
},
101124
html: '',
102125
loading: false,
@@ -108,7 +131,9 @@
108131
title: [{validator: validateRequire}],
109132
content: [{validator: validateRequire}]
110133
},
111-
tempRoute: {}
134+
tempRoute: {},
135+
tags: ['python','vue','仓库'],
136+
selectedTags:[]
112137
}
113138
},
114139
computed: {
@@ -127,8 +152,8 @@
127152
},
128153
created() {
129154
if (this.isEdit) {
130-
const id = this.$route.params && this.$route.params.id
131-
this.fetchData({id: id, isedit: this.isEdit})
155+
const articleId = this.$route.params && this.$route.params.id
156+
this.fetchData(articleId, {'isedit': this.isEdit})
132157
}
133158
134159
// Why need to make a copy of this.$route here?
@@ -138,13 +163,11 @@
138163
},
139164
methods: {
140165
141-
submit() {
142-
console.log(this.content)
143-
console.log(this.html)
144-
},
145-
fetchData(queryParam) {
146-
getArticleDetail(queryParam).then(response => {
147-
this.postForm = response.data
166+
fetchData(articleId, queryParam) {
167+
console.log(articleId, queryParam)
168+
getArticleDetail(articleId, queryParam).then(response => {
169+
console.log(response.data)
170+
this.postForm = response
148171
149172
// just for test
150173
// this.postForm.title += ` Article Id:${this.postForm.id}`
@@ -230,14 +253,18 @@
230253

231254
<style lang="scss" scoped>
232255
@import "~@/styles/mixin.scss";
256+
233257
.mavon-edtior-custom {
234258
width: 100%;
235259
min-height: 600px;
236260
}
261+
237262
.createPost-container {
238263
position: relative;
264+
239265
.createPost-main-container {
240266
padding: 10px 50px 20px 50px;
267+
241268
.postInfo-container {
242269
position: relative;
243270
@include clearfix;

src/views/article/edit.vue

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<template>
2+
<create-article :is-edit="true"></create-article>
3+
</template>
4+
5+
<script>
6+
import CreateArticle from './create'
7+
export default {
8+
name: "EditArticle",
9+
components:{CreateArticle}
10+
}
11+
</script>
12+
13+
<style scoped>
14+
15+
</style>

0 commit comments

Comments
 (0)