Skip to content

Instantly share code, notes, and snippets.

@ralphking
Last active April 13, 2016 08:07
Show Gist options
  • Save ralphking/d0871e76083172f38f55af9c4ade3203 to your computer and use it in GitHub Desktop.
Save ralphking/d0871e76083172f38f55af9c4ade3203 to your computer and use it in GitHub Desktop.

Vue Js gists to save time starting a new project

var vm = New Vue({
el: '#requests'
data:{},
methods: {
// get any data (from an api, json, csv etc)
getData: function() {
}
},
ready() {
},
});
// if using vue resource in rails we need to set the csrf token as a header, go it globally like this if you have it in your rails template
Vue.http.headers.common['X-CSRF-TOKEN'] = $('meta[name="csrf-token"]').attr('content')
// 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) {
// error callback
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment