var usersModel = {
list: [
{id: '123', name: 'Vasya'}
],
add: function (id, name) {
this.list.push({id: id, name: name});
},
update: function () {
$.ajax();
},
usersSomeOtherMethod: function () {
/* some code */
},
};
var messagesModel = {
list: [],
add: function (messageText) {
if (messageText !== '') {
this.list.push({id: Math.random(1000), text: messageText});
}
},
update: function () {
$.ajax();
},
};
var app = new Vue({
el: '#app',
data: {
users: usersModel,
messages: messagesModel,
profile: profileModel,
form: {
textareaText: '',
}
},
methods: {
updateAll: function() {
this.users.update();
this.messages.update();
this.profile.update();
},
addButtonClick(e) {
this.messages.add(this.form.textareaText);
this.form.textareaText = '';
}
}
});