node.js图书借阅与归还
时间: 2023-12-20 17:31:58 浏览: 92
```javascript
// 1. 使用Node.js编写图书借阅与归还的后端接口
// 借阅接口
app.post('/borrowBook', (req, res) => {
const { bookId, userId, borrowTime } = req.body;
// 执行借阅操作的代码逻辑
res.send('Book borrowed successfully');
});
// 归还接口
app.post('/returnBook', (req, res) => {
const { borrowId, returnTime } = req.body;
// 执行归还操作的代码逻辑
res.send('Book returned successfully');
});
```
```javascript
// 2. 使用Vue和Express结合实现前后端交互
// Vue前端代码示例
methods: {
borrowBook() {
this.$axios.post('/borrowBook', { bookId: this.bookId, userId: this.userId, borrowTime: new Date() })
.then(response => {
console.log(response.data);
});
},
returnBook() {
this.$axios.post('/returnBook', { borrowId: this.borrowId, returnTime: new Date() })
.then(response => {
console.log(response.data);
});
}
}
// Express后端代码示例
app.post('/borrowBook', (req, res) => {
const { bookId, userId, borrowTime } = req.body;
// 执行借阅操作的代码逻辑
res.send('Book borrowed successfully');
});
app.post('/returnBook', (req, res) => {
const { borrowId, returnTime } = req.body;
// 执行归还操作的代码逻辑
res.send('Book returned successfully');
});
```
阅读全文