vueGroup.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. const requestFunc = async(url, method = "GET", data = null, token = null) => {
  2. apihost = 'http://schedule.tomtit.tomsk.ru/api'
  3. method = method.toLocaleUpperCase()
  4. let fullurl = `${apihost}${url}`;
  5. let options = {
  6. method: method,
  7. headers: {
  8. "Content-Type": "application/json",
  9. "Authorization": `Bearer ${token}`,
  10. },
  11. };
  12. switch(method) {
  13. case "PUT":
  14. delete options.headers["Content-Type"];
  15. options.body = data;
  16. break;
  17. case "POST": case "PATCH": case "DELETE":
  18. options.body = JSON.stringify(data);
  19. break;
  20. }
  21. const res = await fetch(fullurl, options);
  22. return await res.json();
  23. };
  24. <<<<<<< HEAD
  25. <<<<<<< HEAD
  26. var app = new Vue({
  27. =======
  28. var vueapp = new Vue({
  29. >>>>>>> master
  30. =======
  31. var app = new Vue({
  32. >>>>>>> b5fe990a18b258e28401117b0be0a70e1a10db12
  33. el: '#app',
  34. delimiters: ['${', '}'],
  35. data: {
  36. groups:[],
  37. teachers:[],
  38. <<<<<<< HEAD
  39. <<<<<<< HEAD
  40. selected:null
  41. },
  42. =======
  43. specialties:[],
  44. },
  45. >>>>>>> master
  46. =======
  47. selected:null
  48. },
  49. >>>>>>> b5fe990a18b258e28401117b0be0a70e1a10db12
  50. methods: {
  51. showGroups() {
  52. console.log(this.groups)
  53. },
  54. async getGroups(){
  55. this.groups = await requestFunc("/group/", "GET")
  56. },
  57. async getTeachers(){
  58. teachers = await requestFunc("/teacher/", "GET")
  59. for(let i =0; i < teachers.length; i++) {
  60. Vue.set(this.teachers, i, teachers[i]);
  61. }
  62. },
  63. <<<<<<< HEAD
  64. <<<<<<< HEAD
  65. async mountFunc(){
  66. await this.getTeachers()
  67. await this.getGroups()
  68. },
  69. =======
  70. async getSpecilties(){
  71. specialties = await requestFunc("/specialty/", "GET")
  72. for(let i =0; i < specialties.length; i++) {
  73. Vue.set(this.specialties, i, specialties[i]);
  74. }
  75. },
  76. async mountFunc(){
  77. await this.getTeachers()
  78. await this.getGroups()
  79. await this.getSpecilties()
  80. }
  81. >>>>>>> master
  82. =======
  83. async mountFunc(){
  84. await this.getTeachers()
  85. await this.getGroups()
  86. },
  87. >>>>>>> b5fe990a18b258e28401117b0be0a70e1a10db12
  88. },
  89. async mounted() {
  90. await this.mountFunc()
  91. console.log(this.teachers)
  92. }
  93. });
  94. <<<<<<< HEAD
  95. <<<<<<< HEAD
  96. =======
  97. >>>>>>> b5fe990a18b258e28401117b0be0a70e1a10db12
  98. // const requestFunc = async(url, method = "GET", data = null, token = null) => {
  99. // apihost = 'http://schedule.tomtit.tomsk.ru/api'
  100. // method = method.toLocaleUpperCase()
  101. // let fullurl = `${apihost}${url}`;
  102. // let options = {
  103. // method: method,
  104. // headers: {
  105. // "Content-Type": "application/json",
  106. // "Authorization": `Bearer ${token}`,
  107. // },
  108. // };
  109. <<<<<<< HEAD
  110. // switch(method) {
  111. // case "PUT":
  112. // delete options.headers["Content-Type"];
  113. // options.body = data;
  114. // break;
  115. // case "POST": case "PATCH": case "DELETE":
  116. // options.body = JSON.stringify(data);
  117. // break;
  118. // }
  119. // const res = await fetch(fullurl, options);
  120. // return await res.json();
  121. // };
  122. // var app = new Vue({
  123. // el: '#app',
  124. // delimiters: ['${', '}'],
  125. // data: {
  126. // groups:[],
  127. // teachers:[],
  128. // profmoduls:[],
  129. // },
  130. // methods: {
  131. // showGroups() {
  132. // console.log(this.groups)
  133. // },
  134. // async getGroups(){
  135. // this.groups = await requestFunc("/group/", "GET")
  136. // },
  137. // async getTeachers(){
  138. // teachers = await requestFunc("/teacher/", "GET")
  139. // for(let i =0; i < teachers.length; i++) {
  140. // Vue.set(this.teachers, i, teachers[i]);
  141. // },
  142. // },
  143. // async mountFunc(){
  144. // await this.getTeachers()
  145. // await this.getGroups()
  146. // },
  147. // },
  148. // async mounted() {
  149. // await this.mountFunc()
  150. // console.log(this.teachers)
  151. // }
  152. // });
  153. =======
  154. =======
  155. >>>>>>> b5fe990a18b258e28401117b0be0a70e1a10db12
  156. // switch(method) {
  157. // case "PUT":
  158. // delete options.headers["Content-Type"];
  159. // options.body = data;
  160. // break;
  161. // case "POST": case "PATCH": case "DELETE":
  162. // options.body = JSON.stringify(data);
  163. // break;
  164. // }
  165. <<<<<<< HEAD
  166. >>>>>>> master
  167. =======
  168. // const res = await fetch(fullurl, options);
  169. // return await res.json();
  170. // };
  171. // var app = new Vue({
  172. // el: '#app',
  173. // delimiters: ['${', '}'],
  174. // data: {
  175. // groups:[],
  176. // teachers:[],
  177. // profmoduls:[],
  178. // },
  179. // methods: {
  180. // showGroups() {
  181. // console.log(this.groups)
  182. // },
  183. // async getGroups(){
  184. // this.groups = await requestFunc("/group/", "GET")
  185. // },
  186. // async getTeachers(){
  187. // teachers = await requestFunc("/teacher/", "GET")
  188. // for(let i =0; i < teachers.length; i++) {
  189. // Vue.set(this.teachers, i, teachers[i]);
  190. // },
  191. // },
  192. // async mountFunc(){
  193. // await this.getTeachers()
  194. // await this.getGroups()
  195. // },
  196. // },
  197. // async mounted() {
  198. // await this.mountFunc()
  199. // console.log(this.teachers)
  200. // }
  201. // });
  202. >>>>>>> b5fe990a18b258e28401117b0be0a70e1a10db12