CourseList.vue 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <template>
  2. <div>
  3. <v-container class="ma-8 pa-4">
  4. <v-row>
  5. <router-link :to="`/teacher/create`">
  6. <v-btn class="ma-4 mb-8" fab dark color="indigo">
  7. <v-icon dark large>
  8. mdi-plus
  9. </v-icon>
  10. </v-btn>
  11. </router-link>
  12. </v-row>
  13. <v-row>
  14. <course-item-teacher
  15. v-for="course in courseList"
  16. :key="course.id"
  17. :courseName="course.name"
  18. :courseId="course.id"
  19. :description="course.intro"
  20. :type="course.type"
  21. :cost="course.cost"
  22. :bought="course.bought"
  23. :manageable="course.manageable"
  24. :course-color="colorList[course.id % colorList.length]"
  25. >
  26. </course-item-teacher>
  27. </v-row>
  28. </v-container>
  29. </div>
  30. </template>
  31. <script>
  32. import CourseItemTeacher from "@/components/CourseItemTeacher.vue";
  33. import { getTeacherCourses } from "@/api/course";
  34. export default {
  35. name: "CourseList",
  36. components: {
  37. CourseItemTeacher
  38. },
  39. data() {
  40. return {
  41. colorList: ["#26A69A", "#00B0FF", "#5C6BC0", "#FFB300", "#E57373"],
  42. courseList: null
  43. };
  44. },
  45. mounted() {
  46. const uid = window.localStorage.getItem("userId");
  47. if (uid) {
  48. getTeacherCourses(uid).then(res => {
  49. console.log(res);
  50. this.courseList = res || [];
  51. });
  52. }
  53. }
  54. };
  55. </script>