I'm so new to Vue it hurts. I struggled through Hell and high water to get a small chat app going, as some of you will see from looking at my profile. I finally got it going only to realize that the newest messages are at the bottom and without timestamps, unlike the ones above it. Is there a way to add a timestamp and reverse the .push so the newest message is at the top?
app.js
/**
* First we will load all of this project's JavaScript dependencies which
* includes Vue and other libraries. It is a great starting point when
* building robust, powerful web applications using Vue and Laravel.
*/
require('./bootstrap');
window.Vue = require('vue');
/**
* Next, we will create a fresh Vue application instance and attach it to
* the page. Then, you may begin adding components to this application
* or customize the JavaScript scaffolding to fit your unique needs.
*/
Pusher.logToConsole = true;
Vue.component('example', require('./components/Example.vue'));
Vue.component('chat-messages', require('./components/ChatMessages.vue'));
Vue.component('chat-form', require('./components/ChatForm.vue'));
const app = new Vue({
el: '#app',
data: {
chat_messages: []
},
created() {
this.fetchChatMessages();
Echo.private('chat')
.listen('ChatMessageSent', (e) => {
this.chat_messages.push({
body: e.message.body,
user: e.user
});
});
},
methods: {
fetchChatMessages() {
axios.get('/chitterings/chat/messages').then(response => {
this.chat_messages = response.data;
});
},
addChatMessage(message) {
this.chat_messages.push(message);
axios.post('/chitterings/chat/send', message).then(response => {
console.log(response.data);
});
}
}
});
Thanks in advance. I'm off to go read more things about Vue.