У меня есть метод:
props: ['convId'],
data() {
return {
messages: [],
newMessage: ''
};
},
methods: {
sendMessage() {
axios.post('/sendMessage/' + this.convId, { message: this.newMessage })
.then(response => this.messages.push(response.data.data));
this.messages.push(newMessage);
this.newMessage = '';
console.log(this.messages.id); //TypeError: Cannot read property 'id' of undefined
}
},
Когда я пытаюсь обновить this.messages.Я получаю неопределенные свойства этого объекта.Почему?
В запросе я возвращаю объект:
{"body":"test","user_id":1,"type":"text","conversation_id":1,"updated_at":"2018-06-04 13:15:27","created_at":"2018-06-04 13:15:27","id":16,"conversation":{"id":1,"private":1,"data":null,"created_at":"2018-06-01 12:54:33","updated_at":"2018-06-04 13:15:27","users":[{"id":1,"name":"Axer","email":"test@gmail.com","created_at":"2018-06-01 12:35:37","updated_at":"2018-06-01 12:35:37","pivot":{"conversation_id":1,"user_id":1,"created_at":"2018-06-01 12:54:33","updated_at":"2018-06-01 12:54:33"}},{"id":2,"name":"Testumus","email":"teadasdasd@gmail.com","created_at":"2018-06-01 12:46:30","updated_at":"2018-06-01 12:46:30","pivot":{"conversation_id":1,"user_id":2,"created_at":"2018-06-01 12:54:33","updated_at":"2018-06-01 12:54:33"}}]}}
Как я могу это исправить?