Added fetch api for login

This commit is contained in:
RemixDev
2021-02-25 22:26:05 +01:00
parent 509f940afd
commit 632ca94975
6 changed files with 169 additions and 228 deletions

10
src/utils/api.js Normal file
View File

@@ -0,0 +1,10 @@
export const get = function(key, data){
let url = `/api/${key}`
if (data){
let query = Object.keys(data)
.map(k => encodeURIComponent(k) + '=' + encodeURIComponent(data[k]))
.join('&')
url += '?'+query
}
return fetch(url).then(response => response.json())
}

View File

@@ -3,19 +3,15 @@ import store from '@/store'
class CustomSocket extends WebSocket {
constructor(args) {
super(args)
console.log(args)
}
emit(key, data) {
console.log("emit:", key, data)
console.log(this.readyState)
if (this.readyState != WebSocket.OPEN) return false
this.send(JSON.stringify({key:key, data:data}))
}
on(key, callback) {
this.addEventListener('message', function(event){
console.log(event.data)
let data = JSON.parse(event.data)
if (data.key == key) callback(data.data)
})