Vue Js gists to save time starting a new project
Last active
April 13, 2016 08:07
-
-
Save ralphking/d0871e76083172f38f55af9c4ade3203 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var vm = New Vue({ | |
el: '#requests' | |
data:{}, | |
methods: { | |
// get any data (from an api, json, csv etc) | |
getData: function() { | |
} | |
}, | |
ready() { | |
}, | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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