vis-requestor
v1.4.6
Published
A promise wrap for jQuery ajax
Downloads
93
Readme
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'})
})
}
}
}