1.4.6 • Published 8 months ago

vis-requestor v1.4.6

Weekly downloads
19
License
MIT
Repository
-
Last release
8 months ago

vis-requestor

A promise wrap for jQuery ajax

Install

npm install vis-requestor

Usage

Create a requestor instance

ajax.js

import requestor from 'vis-requestor'

let config = {
  onSessionExpired: function () {
    document.location.replace('http://www.domain.com/login')
  },

  token: {
    checkBeforeSend: true,
    addToHeader: true,
    cookieName: 'token',
    headerName: 'X-Token'
  },

  ajaxOption: {
    method: 'POST'
  },

  resultCode: {
    SESSION_EXPIRED: 304,
    SUCCEED: 200
  },

  urlOption: {
    host: 'http://www.domain.com',
    port: '',
    base: '/module',
  },

  alert: function (msg) {
    window.alert(msg)
    // bootbox.alert(msg)
  },

  failedMsg: 'Request failed, Please retry again later!'
}

let ajax = requestor(config)

export default ajax

Send request in vue component

import ajax from './ajax'

export default {
  methods: {
    submit () {
      ajax.requestAPI({url: '/api_url'}, this.form).then(function () {
        this.$router.go({name: 'list-page-name'})
      })
    }
  }
}
1.4.6

8 months ago

1.4.5

3 years ago

1.4.4

3 years ago

1.4.3

3 years ago

1.4.2

4 years ago

1.4.1

6 years ago

1.4.0

6 years ago

1.3.9

6 years ago

1.3.8

6 years ago

1.3.7

7 years ago

1.3.6

7 years ago

1.3.5

7 years ago

1.3.4

7 years ago

1.3.3

7 years ago

1.3.2

7 years ago

1.3.1

7 years ago

1.3.0

7 years ago

1.2.1

7 years ago

1.2.0

7 years ago

1.0.11

7 years ago

1.0.10

7 years ago

1.0.9

7 years ago

1.0.8

7 years ago

1.0.7

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago