Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
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], [success], [options])
post(url, [data], [success], [options])
put(url, [data], [success], [options])
patch(url, [data], [success], [options])
delete(url, [data], [success], [options])
jsonp(url, [data], [success], [options])
string
- URL to which the request is sentObject|string
- Data to be sent as the request message datastring
- HTTP method (e.g. GET, POST, ...)Object
- Parameters object to be appended as GET parametersObject
- Headers object to be sent as HTTP request headersfunction(data, status, request)
- Callback function to be called when the request finishesfunction(data, status, request)
- Callback function to be called when the request failsfunction(request, options)
- 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 requestnew Vue({
ready: function() {
// GET request
this.$http.get('/someUrl', function (data, status, request) {
// set data on vm
this.$set('someData', data)
}).error(function (data, status, request) {
// 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}, function (item, status, request) {
this.$set('item', item)
})
// save item
resource.save({id: 1}, {item: this.item}, function (data, status, request) {
// handle success
}).error(function (data, status, request) {
// handle error
})
// delete item
resource.delete({id: 1}, function (data, status, request) {
// handle success
}).error(function (data, status, request) {
// handle error
})
}
})
FAQs
The HTTP client for Vue.js
The npm package vue-resource receives a total of 55,261 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.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.