vis-requestor
A promise wrap for jQuery ajax
Last updated a year ago by fe-vis-vipshop .
MIT · Original npm · Tarball · package.json
$ cnpm install vis-requestor 
SYNC missed versions from official npm registry.

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'})
      })
    }
  }
}

Current Tags

  • 1.4.1                                ...           latest (a year ago)

25 Versions

  • 1.4.1                                ...           a year ago
  • 1.4.0                                ...           a year ago
  • 1.3.9                                ...           2 years ago
  • 1.3.8                                ...           2 years ago
  • 1.3.7                                ...           2 years ago
  • 1.3.6                                ...           2 years ago
  • 1.3.5                                ...           2 years ago
  • 1.3.4                                ...           2 years ago
  • 1.3.3                                ...           2 years ago
  • 1.3.2                                ...           3 years ago
  • 1.3.1                                ...           3 years ago
  • 1.3.0                                ...           3 years ago
  • 1.2.1                                ...           3 years ago
  • 1.2.0                                ...           3 years ago
  • 1.0.11                                ...           3 years ago
  • 1.0.10                                ...           3 years ago
  • 1.0.9                                ...           3 years ago
  • 1.0.8                                ...           3 years ago
  • 1.0.7                                ...           3 years ago
  • 1.0.5                                ...           3 years ago
  • 1.0.4                                ...           3 years ago
  • 1.0.3                                ...           3 years ago
  • 1.0.2                                ...           3 years ago
  • 1.0.1                                ...           3 years ago
  • 1.0.0                                ...           3 years ago
Maintainers (1)
Downloads
Today 2
This Week 3
This Month 82
Last Day 1
Last Week 50
Last Month 136
Dependencies (1)
Dev Dependencies (23)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |