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) // } // });