Security News
The Risks of Misguided Research in Supply Chain Security
Snyk's use of malicious npm packages for research raises ethical concerns, highlighting risks in public deployment, data exfiltration, and unauthorized testing.
vue-resource
Advanced tools
Resource plugin for Vue.js.
The plugin provides services for making web requests and handle responses using a XMLHttpRequest or JSONP.
Add vue
and vue-resource
to your package.json
, then npm install
, then add these lines in your code:
var Vue = require('vue');
Vue.use(require('vue-resource'));
Set default values using the global configuration.
Vue.http.options.root = '/root';
Vue.http.headers.common['Authorization'] = 'Basic YXBpOnBhc3N3b3Jk';
Set default values inside your Vue component options.
new Vue({
http: {
root: '/root',
headers: {
Authorization: 'Basic YXBpOnBhc3N3b3Jk'
}
}
})
The http service can be used globally Vue.http
or in a Vue instance this.$http
.
get(url, [data], [options])
post(url, [data], [options])
put(url, [data], [options])
patch(url, [data], [options])
delete(url, [data], [options])
jsonp(url, [data], [options])
string
- URL to which the request is sentstring
- HTTP method (e.g. GET, POST, ...)Object|string
- Data to be sent as the request message dataObject
- Parameters object to be appended as GET parametersObject
- Headers object to be sent as HTTP request headersfunction(request)
- Callback function to modify the request object before it is sentboolean
- Send PUT, PATCH and DELETE requests with a HTTP POST and set the X-HTTP-Method-Override
headerboolean
- Send request data as application/x-www-form-urlencoded
content typeObject
- Parameters object to be set on the native XHR objectstring
- Callback function name in a JSONP requestnumber
- Request timeout in milliseconds (0
means no timeout)new Vue({
ready: function() {
// GET request
this.$http.get('/someUrl').then(function (response) {
// get status
response.status;
// get all headers
response.headers();
// get 'expires' header
response.headers('expires');
// set data on vm
this.$set('someData', response.data)
}, function (response) {
// handle error
});
}
})
The resource service can be used globally Vue.resource
or in a Vue instance this.$resource
.
resource(url, [params], [actions], [options])
get: {method: 'GET'},
save: {method: 'POST'},
query: {method: 'GET'},
update: {method: 'PUT'},
remove: {method: 'DELETE'},
delete: {method: 'DELETE'}
new Vue({
ready: function() {
var resource = this.$resource('someItem{/id}');
// get item
resource.get({id: 1}).then(function (response) {
this.$set('item', response.item)
});
// save item
resource.save({id: 1}, {item: this.item}).then(function (response) {
// handle success
}, function (response) {
// handle error
});
// delete item
resource.delete({id: 1}).then(function (response) {
// handle success
}, function (response) {
// handle error
});
}
})
Interceptors can be defined globally and are used for pre- and postprocessing of a request.
Vue.http.interceptors.push({
request: function (request) {
return request;
},
response: function (response) {
return response;
}
});
If Promises are needed inside of a Interceptor, a factory function can be used.
Vue.http.interceptors.push(function (Promise) {
return {
request: function (request) {
if (reject) {
return Promise.reject();
}
},
response: function (response) {
if (reject) {
return Promise.reject();
}
}
};
});
FAQs
The HTTP client for Vue.js
The npm package vue-resource receives a total of 83,704 weekly downloads. As such, vue-resource popularity was classified as popular.
We found that vue-resource demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Snyk's use of malicious npm packages for research raises ethical concerns, highlighting risks in public deployment, data exfiltration, and unauthorized testing.
Research
Security News
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.