1.4.6 • Published 2 years ago

vis-requestor v1.4.6

Weekly downloads
19
License
MIT
Repository
-
Last release
2 years 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

2 years ago

1.4.5

4 years ago

1.4.4

4 years ago

1.4.3

4 years ago

1.4.2

5 years ago

1.4.1

7 years ago

1.4.0

7 years ago

1.3.9

7 years ago

1.3.8

7 years ago

1.3.7

8 years ago

1.3.6

8 years ago

1.3.5

8 years ago

1.3.4

8 years ago

1.3.3

8 years ago

1.3.2

8 years ago

1.3.1

8 years ago

1.3.0

8 years ago

1.2.1

8 years ago

1.2.0

8 years ago

1.0.11

8 years ago

1.0.10

8 years ago

1.0.9

8 years ago

1.0.8

8 years ago

1.0.7

9 years ago

1.0.5

9 years ago

1.0.4

9 years ago

1.0.3

9 years ago

1.0.2

9 years ago

1.0.1

9 years ago

1.0.0

9 years ago