Skip to content

Instantly share code, notes, and snippets.

@nemanja947
Created December 17, 2018 14:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nemanja947/0a118bd2a459557af3eb1d249183892c to your computer and use it in GitHub Desktop.
Save nemanja947/0a118bd2a459557af3eb1d249183892c to your computer and use it in GitHub Desktop.
class UserModel {
construct(data) {
this.data = data
}
name() {
return this.data.firstname + ' ' + this.data.lastname
}
// and so on, put other methods here
}
var app = new Vue({
el: '#app',
data: {
user: {}
},
created() {
// axios or anything else for your ajax, or a new fetch api
axios.get('/me')
.then(response => {
// of course the "this" here is the Vue instance because i used an es6 arrow function
this.user = new UserModel(response.data)
})
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment