mirror of
https://github.com/docker-training/node-bulletin-board.git
synced 2025-12-15 07:16:43 +08:00
Add v4, with proxy, app and db
This commit is contained in:
54
bulletin-board-app/app.js
Normal file
54
bulletin-board-app/app.js
Normal file
@@ -0,0 +1,54 @@
|
||||
new Vue({
|
||||
el: '#events',
|
||||
|
||||
data: {
|
||||
event: { title: '', detail: '', date: '' },
|
||||
events: []
|
||||
},
|
||||
|
||||
ready: function () {
|
||||
this.fetchEvents();
|
||||
},
|
||||
|
||||
methods: {
|
||||
|
||||
fetchEvents: function () {
|
||||
var events = [];
|
||||
this.$http.get('/api/events')
|
||||
.success(function (events) {
|
||||
this.$set('events', events);
|
||||
console.log(events);
|
||||
})
|
||||
.error(function (err) {
|
||||
console.log(err);
|
||||
});
|
||||
},
|
||||
|
||||
addEvent: function () {
|
||||
if (this.event.title.trim()) {
|
||||
this.$http.post('/api/events', this.event)
|
||||
.success(function (res) {
|
||||
this.events.push(this.event);
|
||||
console.log('Event added!');
|
||||
})
|
||||
.error(function (err) {
|
||||
console.log(err);
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
deleteEvent: function (id) {
|
||||
if (confirm('Are you sure you want to delete this event?')) {
|
||||
this.$http.delete('api/events/' + id)
|
||||
.success(function (res) {
|
||||
console.log(res);
|
||||
var index = this.events.find(x => x.id === id)
|
||||
this.events.splice(index, 1);
|
||||
})
|
||||
.error(function (err) {
|
||||
console.log(err);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user