123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- const requestFunc = async(url, method = "GET", data = null, token = null) => {
- apihost = 'http://schedule.tomtit.tomsk.ru/api'
- method = method.toLocaleUpperCase()
- let fullurl = `${apihost}${url}`;
- let options = {
- method: method,
- headers: {
- "Content-Type": "application/json",
- "Authorization": `Bearer ${token}`,
- },
- };
- switch(method) {
- case "PUT":
- delete options.headers["Content-Type"];
- options.body = data;
- break;
- case "POST": case "PATCH": case "DELETE":
- options.body = JSON.stringify(data);
- break;
- }
- const res = await fetch(fullurl, options);
- return await res.json();
- };
- var app = new Vue({
- el: '#app',
- delimiters: ['${', '}'],
- data: {
- groups:[],
- teachers:[],
- selected:null
- },
- methods: {
- showGroups() {
- console.log(this.groups)
- },
- async getGroups(){
- this.groups = await requestFunc("/group/", "GET")
- },
- async getTeachers(){
- teachers = await requestFunc("/teacher/", "GET")
- for(let i =0; i < teachers.length; i++) {
- Vue.set(this.teachers, i, teachers[i]);
- }
- },
- async mountFunc(){
- await this.getTeachers()
- await this.getGroups()
- },
- },
- async mounted() {
- await this.mountFunc()
- console.log(this.teachers)
- }
- });
- // const requestFunc = async(url, method = "GET", data = null, token = null) => {
- // apihost = 'http://schedule.tomtit.tomsk.ru/api'
- // method = method.toLocaleUpperCase()
- // let fullurl = `${apihost}${url}`;
- // let options = {
- // method: method,
- // headers: {
- // "Content-Type": "application/json",
- // "Authorization": `Bearer ${token}`,
- // },
- // };
- // switch(method) {
- // case "PUT":
- // delete options.headers["Content-Type"];
- // options.body = data;
- // break;
- // case "POST": case "PATCH": case "DELETE":
- // options.body = JSON.stringify(data);
- // break;
- // }
- // const res = await fetch(fullurl, options);
- // return await res.json();
- // };
- // var app = new Vue({
- // el: '#app',
- // delimiters: ['${', '}'],
- // data: {
- // groups:[],
- // teachers:[],
- // profmoduls:[],
- // },
- // methods: {
- // showGroups() {
- // console.log(this.groups)
- // },
- // async getGroups(){
- // this.groups = await requestFunc("/group/", "GET")
- // },
- // async getTeachers(){
- // teachers = await requestFunc("/teacher/", "GET")
- // for(let i =0; i < teachers.length; i++) {
- // Vue.set(this.teachers, i, teachers[i]);
- // },
- // },
- // async mountFunc(){
- // await this.getTeachers()
- // await this.getGroups()
- // },
- // },
- // async mounted() {
- // await this.mountFunc()
- // console.log(this.teachers)
- // }
- // });
|