零基础快速开发Vue图书管理系统—主体列表实现篇(二)

简介: 代码如下

零基础快速开发Vue图书管理系统—主体列表实现篇(二)

一、主体列表的基本布局

2345_image_file_copy_518.jpg

❤️Header部分

2345_image_file_copy_519.jpg

<template>
  <div class="basic-layout">
    <div class="app-header">
       <div class="left">
        <img src="https://ncstatic.clewm.net/rsrc/2020/1016/02/4757e4910cb527fc040d019a93ded74f.png?x-oss-process=image/resize,w_750/format,gif/sharpen,100/quality,Q_80/interlace,1/auto-orient,1"
                alt="">
           <div class="title">图书管理系统</div>
       </div>
       <div class="right">
        <div class="hello-msg">你好,XX</div>
            <div class="logout">退出</div>
       </div>
    </div>
    <div class="app-content">
        <div class="left">
        </div>
        <div class="right">
        </div>
    </div>
  </div>
</template>

2345_image_file_copy_520.jpg

二、设计书籍的Schema

2345_image_file_copy_521.jpg

三、编写添加书籍接口与查询全部书籍的接口

2345_image_file_copy_522.jpg

const Router = require('@koa/router');
const mongoose = require('mongoose');
const { getBody } = require('../../helpers/utils')
const Book = mongoose.model('Book');
const router = new Router({
    prefix: '/book',
});
router.post('/book', async(ctx) => {
    const {
        name,
        price,
        author,
        publishDate,
        classify
    } = getBody(ctx);
    const book = new Book({
        name,
        price,
        author,
        publishDate,
        classify
    });
    const res = await book.save();
    ctx.body = {
        data: res,
        code: 1,
        msg: '添加成功'
    };
});
router.get('/list', async(ctx) => {
    const list = await Book.find().exec();
    ctx.body = {
        data: list,
        code: 1,
        msg: '获取列表成功'
    };
});
module.exports = router;

四、实现添加弹窗和接口对接

需求:点击增加一条按钮,出现弹框

2345_image_file_copy_523.jpg

2345_image_file_copy_524.jpg

2345_image_file_copy_525.jpg

<template>
    <div>
        <a-modal title="添加书籍" :visible="true" @ok="submit">
            <a-form :label-col="{ span:6  }">
                <a-form-item label="书名">
                    <a-input v-model:value="addForm.name" />
                </a-form-item>
                <a-form-item label="价格">
                    <a-input-number v-model:value="addForm.price" :min="0" :max="9999999" />
                </a-form-item>
                <a-form-item label="作者">
                    <a-input v-model:value="addForm.author" />
                </a-form-item>
                <a-form-item label="出版日期">
                    <a-date-picker v-model:value="addForm.publishDate" />
                </a-form-item>
                <a-form-item label="分类">
                    <a-input v-model:value="addForm.classify" />
                </a-form-item>
            </a-form>
        </a-modal>
    </div>
</template>
<script src="./index.js">
</script>
<style lang="scss" scoped>
    @import './index.scss'
</style>

2345_image_file_copy_526.jpg

2345_image_file_copy_527.jpg

五、实现弹窗的显示隐藏逻辑

功能:点击添加一条按钮出现弹框,点击X的时候关闭弹窗

2345_image_file_copy_528.jpg

2345_image_file_copy_529.jpg

使用v-model实现数据的双向绑定

2345_image_file_copy_530.jpg

2345_image_file_copy_531.jpg

2345_image_file_copy_532.jpg

六、书籍列表接口联调

2345_image_file_copy_533.jpg

2345_image_file_copy_534.jpg

2345_image_file_copy_535.jpg

2345_image_file_copy_536.jpg

七、书籍列表分页功能实现

2345_image_file_copy_537.jpg

2345_image_file_copy_538.jpg

2345_image_file_copy_539.jpg

2345_image_file_copy_540.jpg

2345_image_file_copy_541.jpg

<template>
    <div>
        <a-card>
            <h2>图书列表</h2>
            <a-divider />
            <space-between>
                <div class="search">
                    <a-input-search placeholder="根据书名搜索" enter-button />
                </div>
                <a-button @click="show=true">添加一条</a-button>
            </space-between>
            <a-divider />
            <a-table 
            :data-source="list" 
            :columns="columns"
            :pagination="false"
             >
        <template #publishDate="data">
        {{formatTimestamp(data.record.publishDate)}}
        </template>
        </a-table>
        <space-between style="margin-top:23px">
            <div/>
            <a-pagination 
            v-model:current="curPage" 
            :total="total"
            :page-size="10"
            @change="setPage"
            />
        </space-between>
        </a-card>
        <add-one v-model:show="show" />
    </div>
</template>
<script src="./index.js">
</script>
<style lang="scss" scoped>
    @import './index.scss'
</style>


相关文章
|
JavaScript
Vue中如何实现兄弟组件之间的通信
在Vue中,兄弟组件可通过父组件中转、事件总线、Vuex/Pinia或provide/inject实现通信。小型项目推荐父组件中转或事件总线,大型项目建议使用Pinia等状态管理工具,确保数据流清晰可控,避免内存泄漏。
1057 2
|
缓存 JavaScript
vue中的keep-alive问题(2)
vue中的keep-alive问题(2)
928 137
|
人工智能 JavaScript 算法
Vue 中 key 属性的深入解析:改变 key 导致组件销毁与重建
Vue 中 key 属性的深入解析:改变 key 导致组件销毁与重建
2227 0
|
JavaScript UED
用组件懒加载优化Vue应用性能
用组件懒加载优化Vue应用性能
|
缓存 前端开发 大数据
虚拟列表在Vue3中的具体应用场景有哪些?
虚拟列表在 Vue3 中通过仅渲染可视区域内容,显著提升大数据列表性能,适用于 ERP 表格、聊天界面、社交媒体、阅读器、日历及树形结构等场景,结合 `vue-virtual-scroller` 等工具可实现高效滚动与交互体验。
1415 1
|
人工智能 JSON JavaScript
VTJ.PRO 首发 MasterGo 设计智能识别引擎,秒级生成 Vue 代码
VTJ.PRO发布「AI MasterGo设计稿识别引擎」,成为全球首个支持解析MasterGo原生JSON文件并自动生成Vue组件的AI工具。通过双引擎架构,实现设计到代码全流程自动化,效率提升300%,助力企业降本增效,引领“设计即生产”新时代。
1120 1
|
JavaScript 安全
在 Vue 中,如何在回调函数中正确使用 this?
在 Vue 中,如何在回调函数中正确使用 this?
845 0
|
JavaScript
vue实现任务周期cron表达式选择组件
vue实现任务周期cron表达式选择组件
1795 4
|
JavaScript 数据可视化 前端开发
基于 Vue 与 D3 的可拖拽拓扑图技术方案及应用案例解析
本文介绍了基于Vue和D3实现可拖拽拓扑图的技术方案与应用实例。通过Vue构建用户界面和交互逻辑,结合D3强大的数据可视化能力,实现了力导向布局、节点拖拽、交互事件等功能。文章详细讲解了数据模型设计、拖拽功能实现、组件封装及高级扩展(如节点类型定制、连接样式优化等),并提供了性能优化方案以应对大数据量场景。最终,展示了基础网络拓扑、实时更新拓扑等应用实例,为开发者提供了一套完整的实现思路和实践经验。
2123 78
|
缓存 JavaScript 前端开发
Vue 基础语法介绍
Vue 基础语法介绍