例如,我想要一个雇员的collections(或list),而每个雇员都是一个模型
解决
这是一个实现示例(在ES6中):
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) }) } })