vue-request
Advanced tools
Comparing version 1.0.0 to 1.0.1
63
index.js
@@ -1,3 +0,60 @@ | ||
module.exports = function () { | ||
console.log('it is for Vue.js') | ||
} | ||
(function () { | ||
const axios = require('axios') | ||
const pathToRegexp = require('path-to-regexp') | ||
const qs = require('qs') | ||
//create path compiler | ||
function compilePath (path, paramsObj) { | ||
return pathToRegexp.compile(path)(paramsObj) | ||
} | ||
//define vue-request | ||
const VueRequest = {} | ||
/** | ||
* Vue.use(VueRequest, { | ||
* headers: { | ||
* 'Content-Type': 'application/x-www-form-urlencoded' | ||
* } | ||
* }) | ||
* | ||
* this.$http.get(someUrl, data, config) same as axios | ||
* @param {[Object]} options [description] | ||
*/ | ||
VueRequest.install = function (Vue, options) { | ||
const instance = axios.create(options) | ||
instance.interceptors.request.use(function (config) { | ||
if (config.urlParams) { | ||
config.url = compilePath(config.url, config.urlParams) | ||
} | ||
//x-www-form-urlencoded | ||
if (config.headers['Content-Type'] && config.headers['Content-Type'].indexOf('application/x-www-form-urlencoded') !== -1 && config.data) { | ||
config.data = qs.stringify(config.data, {encode: false}) | ||
} | ||
//form data | ||
if (config.headers['Content-Type'] && config.headers['Content-Type'].indexOf('multipart/form-data') !== -1 && config.data) { | ||
const data = config.data | ||
const formData = new FormData() | ||
Object.keys(data).forEach((v,i) => { | ||
formData.append(v, data[v]) | ||
}) | ||
config.data = formData | ||
} | ||
return config | ||
}) | ||
Vue.prototype.$http = instance | ||
} | ||
if (typeof exports == "object") { | ||
module.exports = VueRequest | ||
} else if (typeof define == "function" && define.amd) { | ||
define([], function(){ return VueRequest }) | ||
} else if (typeof window !== 'undefined' && window.Vue) { | ||
Vue.use(VueRequest, options) | ||
} | ||
})() |
{ | ||
"name": "vue-request", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "a http client for Vue.js based on axios", | ||
"main": "index.js", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/xiadd/vue-request" | ||
}, | ||
"scripts": { | ||
@@ -13,3 +17,8 @@ "test": "echo \"Error: no test specified\" && exit 1" | ||
"author": "xiadd", | ||
"license": "ISC" | ||
"license": "ISC", | ||
"devDependencies": { | ||
"axios": "^0.15.3", | ||
"path-to-regexp": "^1.7.0", | ||
"qs": "^6.4.0" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
Trivial Package
Supply chain riskPackages less than 10 lines of code are easily copied into your own project and may not warrant the additional supply chain risk of an external dependency.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
2998
4
51
0
19
0
0
3