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

简介: 代码如下

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

一、实现列表按书名搜索

2345_image_file_copy_542.jpg

2345_image_file_copy_543.jpg2345_image_file_copy_544.jpg

import { defineComponent, ref, onMounted } from 'vue';
import { book } from '@/service'
import { result, formatTimestamp } from '@/helpers/utils'
import { message } from 'ant-design-vue'
import AddOne from './AddOne/index.vue';
export default defineComponent({
    components: {
        AddOne,
    },
    setup() {
        const columns = [{
                title: '书名',
                dataIndex: 'name',
            },
            {
                title: '价格',
                dataIndex: 'price',
            },
            {
                title: '作者',
                dataIndex: 'author',
            },
            {
                title: '出版日期',
                dataIndex: 'publishDate',
                slots: {
                    customRender: 'publishDate'
                }
            },
            {
                title: '分类',
                dataIndex: 'classify',
            },
            {
                title: '操作',
                slots: {
                    customRender: 'actions'
                }
            }
        ];
        const show = ref(false);
        var list = ref([]);
        const total = ref(0);
        const curPage = ref(1);
        const keyword = ref('');
        const isSearch = ref(false)
            //获取书籍列表
        const getList = async() => {
            const res = await book.list({
                page: curPage.value,
                size: 10,
                keyword: keyword.value,
            });
            result(res)
                .success(({ data }) => {
                    const { list: l, total: t } = data;
                    list.value = l;
                    total.value = t;
                })
        };
        onMounted(async() => {
            getList();
        });
        //设置页码
        const setPage = (page) => {
            curPage.value = page;
            getList();
        };
        const onSearch = () => {
            getList();
            //字符串非空的时候 —true
            //字符串为空的时候 -false
            isSearch.value = Boolean(keyword.value);
        };
        //返回全部列表
        const backAll = () => {
            keyword.value = '',
                isSearch.value = false;
            getList();
        };
        //删除一本书籍
        const remove = async({ text: record }) => {
            const { _id } = record;
            const res = await book.remove(_id);
            result(res).success(({ msg }) => {
                message.success(msg);
                // const idx = list.value.findIndex((item) => {
                //     return item._id === _id;
                // });
                // list.value.splice(idx, 1);
                getList();
            })
        }
        return {
            columns,
            show,
            list,
            formatTimestamp,
            curPage,
            total,
            setPage,
            keyword,
            onSearch,
            backAll,
            isSearch,
            remove,
        }
    }
})

二、书籍删除接口实现并与前端联调

2345_image_file_copy_545.jpg

2345_image_file_copy_546.jpg

2345_image_file_copy_547.jpg

2345_image_file_copy_548.jpg

三、书籍库存接口的实现与书籍列表、添加功能的完善

2345_image_file_copy_549.jpg

2345_image_file_copy_550.jpg

相关文章
|
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
|
2天前
|
JavaScript
vue学习(14)深度监视
vue学习(14)深度监视
10 0
|
3天前
|
JavaScript
vue中watch的用法
vue中watch的用法
|
3天前
|
JavaScript 前端开发
vue动态添加style样式
vue动态添加style样式
|
3天前
|
JavaScript 前端开发
Vue项目使用px2rem
Vue项目使用px2rem
|
10天前
|
JavaScript
vue学习(4)数据绑定
vue学习(4)数据绑定
32 10
|
10天前
|
JavaScript 前端开发
vue学习(6)
vue学习(6)
31 9
|
10天前
|
JavaScript 开发者
vue学习(5)
vue学习(5)
24 7