all files / src/ http.js

0% Statements 0/11
0% Branches 0/4
0% Functions 0/7
0% Lines 0/11
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26                                                   
function core(method, url, options) {
  let xhr = new XMLHttpRequest()
  xhr.open(method, url)
  xhr.onload = () => {
    options.success && options.success(xhr.response)
  }
  xhr.onerror = () => {
    options.error && options.error(xhr)
  }
  xhr.send(options.data)
}
export default {
  get(url, options) {
    core('get', url, options)
  },
  post(url, options) {
    core('post', url, options)
  },
  put(url, options) {
    core('put', url, options)
  },
  delete(url, options) {
    core('delete', url, options)
  }
}