diff --git a/src/components/MDinput/index.vue b/src/components/MDinput/index.vue
index 6d9d5e8e..731311f7 100644
--- a/src/components/MDinput/index.vue
+++ b/src/components/MDinput/index.vue
@@ -71,6 +71,11 @@ export default {
}
}
},
+ watch: {
+ value(newValue) {
+ this.currentValue = newValue
+ }
+ },
data() {
return {
currentValue: this.value,
diff --git a/src/mock/article.js b/src/mock/article.js
index f6ed1751..a42030ed 100644
--- a/src/mock/article.js
+++ b/src/mock/article.js
@@ -50,7 +50,7 @@ export default {
author: { key: 'mockPan' },
source_name: '原创作者',
category_item: [{ key: 'global', name: '全球' }],
- comment_disabled: false,
+ comment_disabled: true,
content: '
我是测试数据我是测试数据
"',
content_short: '我是测试数据',
display_time: +new Date(),
@@ -59,6 +59,6 @@ export default {
source_uri: 'https://github.com/PanJiaChen/vue-element-admin',
status: 'published',
tags: [],
- title: ''
+ title: 'vue-element-admin'
})
}
diff --git a/src/views/example/form.vue b/src/views/example/form.vue
index 9a09c846..c0a0a925 100644
--- a/src/views/example/form.vue
+++ b/src/views/example/form.vue
@@ -4,27 +4,28 @@
-
-
-
- 创建form
-
- {{!postForm.comment_disabled?'评论已打开':'评论已关闭'}}
-
-
-
- 关闭评论
- 打开评论
-
-
-
-
-
+
+ 创建form
+
-
- 平台
+ {{!postForm.comment_disabled?'评论已打开':'评论已关闭'}}
+
+
+
+
+
+ 关闭评论
+ 打开评论
+
+
+
+
+
+
+ 平台
+
@@ -37,7 +38,8 @@
- 外链
+ 外链
+
@@ -130,6 +132,19 @@ import { validateURL } from '@/utils/validate'
import { fetchArticle } from '@/api/article'
import { userSearch } from '@/api/remoteSearch'
+const defaultForm = {
+ title: '', // 文章题目
+ content: '', // 文章内容
+ content_short: '', // 文章摘要
+ source_uri: '', // 文章外链
+ image_uri: '', // 文章图片
+ source_name: '', // 文章外部作者
+ display_time: undefined, // 前台展示时间
+ id: undefined,
+ platforms: ['a-platform'],
+ comment_disabled: false
+}
+
export default {
name: 'articleDetail',
components: { Tinymce, MDinput, Upload, Multiselect, Sticky },
@@ -161,24 +176,14 @@ export default {
}
}
return {
- postForm: {
- title: '', // 文章题目
- content: '', // 文章内容
- content_short: '', // 文章摘要
- source_uri: '', // 文章外链
- image_uri: '', // 文章图片
- source_name: '', // 文章外部作者
- display_time: undefined, // 前台展示时间
- id: undefined,
- platforms: ['a-platform']
- },
+ postForm: Object.assign({}, defaultForm),
fetchSuccess: true,
loading: false,
userLIstOptions: [],
platformsOptions: [
- { key: 'a-platform', name: 'a-platform' },
- { key: 'b-platform', name: 'b-platform' },
- { key: 'c-platform', name: 'c-platform' }
+ { key: 'a-platform', name: 'a-platform' },
+ { key: 'b-platform', name: 'b-platform' },
+ { key: 'c-platform', name: 'c-platform' }
],
rules: {
image_uri: [{ validator: validateRequire }],
@@ -202,6 +207,16 @@ export default {
this.fetchData()
}
},
+ watch: {
+ // 如果路由有变化,会再次执行该方法
+ '$route'(to, from) {
+ if (this.isEdit) {
+ this.fetchData()
+ } else {
+ this.postForm = defaultForm
+ }
+ }
+ },
methods: {
fetchData() {
fetchArticle().then(response => {