Skip to content
A tiny library for handling JSONP request.
Branch: master
Clone or download
Latest commit c317251 Apr 28, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
dist
src
test + Fix UMD export. Apr 28, 2018
.babelrc + First commit. Oct 17, 2016
.editorconfig + Add types. Jun 30, 2017
.gitignore
.npmignore + Fix UMD export. Apr 28, 2018
.travis.yml + Remove node4 travis testing. Jun 30, 2017
README.md + Add building status. Jan 24, 2017
gulpfile.js + Fix UMD export. Apr 28, 2018
index.d.ts
package.json

README.md

Vue-jsonp

Travis

A tiny library for handling JSONP request.

Usage.

Static function: Vue.jsonp(url, dataObj, timeout)

In Vue component: this.$jsonp(url, dataObj, timeout)

Params.

  • url: Target url for request.
  • dataObj: Object contains datas for querying.
  • timeout: Timeout for jsonp request.

URL.

'/url?{callbackQuery}={callbackName}&...'

// Default:
'/url?callback=jsonp_RANDOM_STRING&...'

Assign callback query name.

this.$jsonp('/url', {
  callbackQuery: 'cb'  // Default: callback
})

// Then URL will be: '/url?cb=jsonp_aws84739ssu8e3'

Assign callback function name.

this.$jsonp('/url', {
  callbackName: 'jsonpFunc'
})

// Then URL will be: '/url?callback=jsonpFunc'

Example.

import Vue from 'vue'
import VueJsonp from 'vue-jsonp'
Vue.use(VueJsonp)

// If you want to setup the global timeout, just:
Vue.use(VueJsonp, 5000)
// Now all requests will be expired after 5000ms.

// Use it in Vue Component.
const SomeComponent = Vue.extend({
  methods: {
    getData () {
      this.$jsonp('http://www.some-site.com/data', { name: 'MyName', age: 20 }).then(json => {
        // Success.
      }).catch(err => {
        // Failed.
      })
    }
  }
})

// Static Function.
// Request url will be 'http://www.some-site.com/data?name=MyName&age=20&cb=jsonpFunc'
Vue.jsonp('http://www.some-site.com/data', {
  name: 'MyName', age: 20, callbackQuery: 'cb', callbackName: 'jsonpFunc'
}).then(json => {
  // Success.
}).catch(err => {
  // Failed.
})

License

MIT.

You can’t perform that action at this time.