零基础快速开发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>


相关文章
|
3天前
|
JavaScript
vue中watch的用法
vue中watch的用法
|
3天前
|
JavaScript 前端开发
vue动态添加style样式
vue动态添加style样式
|
3天前
|
JavaScript 前端开发
Vue项目使用px2rem
Vue项目使用px2rem
|
2天前
|
JavaScript API
vue学习(13)监视属性
vue学习(13)监视属性
11 2
|
2天前
|
JavaScript
vue 函数化组件
vue 函数化组件
|
2天前
|
JavaScript 前端开发
vue学习(15)watch和computed
vue学习(15)watch和computed
9 1
|
7天前
|
JavaScript 前端开发
Vue项目使用px2rem
Vue项目使用px2rem
|
2天前
|
JavaScript
vue学习(14)深度监视
vue学习(14)深度监视
10 0
|
7天前
|
JavaScript
Vue组件传值异步问题--子组件拿到数据较慢
Vue组件传值异步问题--子组件拿到数据较慢
11 0
|
7天前
|
缓存 JavaScript
Vue中的keep-alive是什么意思?以及如何使用
Vue中的keep-alive是什么意思?以及如何使用