Created
December 17, 2018 14:43
-
-
Save nemanja947/0a118bd2a459557af3eb1d249183892c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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