I am writing a (very) simple datepicker control in vue.js, using moment.js for formatting and mutating the date.
The problem I'm having is that even though the date instance in the component is modified when I click either button, the display does not update.
I've tried changing this to a simple integer instead of a date instance, and that works as expected (the DOM is updated properly)
Here is the source code that I have for this:
App.js
Vue.component("datePicker", { props: ["value"], data: function() { return { selectedDate: moment(this.value) }; }, template: "<div><button v-on:click='decrement'><</button>{{formattedSelectedDate}}<button v-on:click='increment'>></button></div>", methods: { increment: function () { this.selectedDate.add(1, "days"); this.$emit('input', this.selectedDate); }, decrement: function () { this.selectedDate.subtract(1, "days"); this.$emit('input', this.selectedDate); } }, computed: { formattedSelectedDate: function() { return this.selectedDate.format("YYYY-MM-DD"); } } }); var PointTracker = new Vue({ el: "#PointTracker", data: { selectedDate: moment(), todoItems: {} } }); Index.html
<html> <head> <meta charset="utf-8"> <title>Point Tracker</title> <link rel="stylesheet" href="style.css"> </head> <body> <div id="PointTracker"> <date-picker v-model="selectedDate"> </div> <script src="node_modules/moment/moment.js"></script> <script src="node_modules/vue/dist/vue.js"></script> <script src="node_modules/vue-resource/dist/vue-resource.js"></script> <script src="app.js"></script> </body> </html>