ソースを参照

fix: 修正学生界面缺少路由侦听的问题

ChenYangfan 6 年 前
コミット
a8e5ffac9a
1 ファイル変更15 行追加9 行削除
  1. 15 9
      src/views/student/components/StudentCourseDetail.vue

+ 15 - 9
src/views/student/components/StudentCourseDetail.vue

@@ -57,20 +57,26 @@ export default {
     }
   },
   watch: {
-    course () {
-      this.fetchNotices()
+    $route () {
+      this.init()
     }
   },
   created () {
-    getOneCourse({ courseId: this.$route.params.courseId })
-      .then(res => {
-        this.course = res
-        this.fetchNotices()
-      })
-      .catch(err => this.$setErrorMessage(err.response.data.msg))
-    this.fetchNotices()
+    this.init()
   },
   methods: {
+    init() {
+      this.getCourse()
+      this.fetchNotices()
+    },
+    getCourse () {
+      getOneCourse({ courseId: this.$route.params.courseId })
+        .then(res => {
+          this.course = res
+          this.fetchNotices()
+        })
+        .catch(err => this.$setErrorMessage(err.response.data.msg))
+    },
     fetchNotices () {
       getNotices({ courseId: this.course.id }).then(res => {
         this.notices = res.data