Forráskód Böngészése

[新增] path prefix mixin

WuXinyu 7 éve
szülő
commit
3a4478a867
2 módosított fájl, 17 hozzáadás és 5 törlés
  1. 4 5
      src/components/PageHeader/index.jsx
  2. 13 0
      src/mixins/path.js

+ 4 - 5
src/components/PageHeader/index.jsx

@@ -1,4 +1,5 @@
 import { mapState } from "vuex";
+import pathMixin from "@/mixins/path";
 import "./index.scss";
 
 export default {
@@ -15,14 +16,12 @@ export default {
   },
   computed: {
     ...mapState({
-      course: state => state.course.currentCourse,
-      profile: state => state.user.profile
+      course: state => state.course.currentCourse
     })
   },
+  mixins: [pathMixin],
   render() {
-    const { profile, course = {}, routes = [], tabList = [] } = this;
-    const { role = "" } = profile;
-    const prefix = `/course-${role.toLowerCase()}/${course.id}`;
+    const { prefix, course, routes = [], tabList = [] } = this;
     const { logo, title, action, content, extraContent } = this.$slots;
     const showTabs = tabList && tabList.length > 0;
     console.log(prefix);

+ 13 - 0
src/mixins/path.js

@@ -0,0 +1,13 @@
+import { mapState } from "vuex";
+
+export default {
+  computed: {
+    ...mapState({
+      profile: state => state.user.profile
+    }),
+    prefix() {
+      const { role = "" } = this.profile;
+      return `/course-${role.toLowerCase()}/${this.$route.params.courseId}`;
+    }
+  }
+};