Added fetch api for login
This commit is contained in:
10
src/utils/api.js
Normal file
10
src/utils/api.js
Normal 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())
|
||||
}
|
||||
@@ -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)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user