图书管理系统

    技术2025-05-04  16

    使用bootstrap,vue实现图书管理系统,实现增,删,查的功能(不涉及数据库)

    <!--文档声明类型--> <!DOCTYPE html> <!--最外层标签,根标签,lang(language)表示属性为英语--> <html lang="en"> <!--文档的头标签--> <head> <!-- 规定文档的字符编码--> <meta charset="UTF-8"> <title>图书管理系统</title> <!-- 导入vue.js--> <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script> <!-- 最新版本的 Bootstrap 核心 CSS 文件 --> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous"> </head> <body> <!--id为vue的边界--> <div id="app"> <div class="container"> <h1>图书管理系统</h1> <form class="form-inline"> <div class="form-group"> <!-- for属性与id属性绑定--> <label for="name">图书名称</label> <!-- type表示为文本类型,name属性用于传值,placeholder为提示语,v-model:用于input标签,实现数据的联动--> <input type="text" class="form-control" id="name" name="name" placeholder="请输入图书名称" v-model="adding_book.name"> </div> <div class="form-group"> <label for="author">作者</label> <input type="text" class="form-control" id="author" name="author" placeholder="请输入作者" v-model="adding_book.author"> </div> <div class="form-group"> <label for="price">价格</label> <input type="text" class="form-control" id="price" name="price" placeholder="请输入价格" v-model="adding_book.price"> </div> <!-- v-on给元素添加事件,click为鼠标点击事件,prevent用来阻止事件的默认行为--> <button type="submit" class="btn btn-primary" v-on:click.prevent="add">添加</button> </form> <form class="form-inline"> <div class="form-group"> <label for="keywords">搜索关键字:</label> <input type="text" class="form-control" id="keywords" name="keywords" placeholder="请输入关键字" v-model="keywords"> </div> </form> <!-- 表格表头的布局--> <table class="table"> <thead> <!-- tablerow表头,tableheadercell表头单元格--> <tr> <th>序号</th> <th>名称</th> <th>作者</th> <th>价格</th> <th>时间</th> <th>操作</th> </tr> </thead> <tbody> <!-- tabledatacell表中的数据单元--> <tr v-for="(book,index) in book_result"> <td>{{ index+1 }}</td> <td>{{ book.name }}</td> <td>{{ book.author }}</td> <td>{{ book.price }}</td> <td>{{ book.date|timeFormat }}</td> <td><button class="btn btn-danger btn-xs" @click="del(index)">删除</button></td> </tr> </tbody> </table> </div> </div> <!--用于定义客户端脚本--> <script> // 新建Vue对象 new Vue({ // 指定管理界限 el: '#app', data: { books: [ {"name": "三国演义", "author": "罗贯中", "price": 100, "date": new Date()} ], adding_book: { name: "", author: "", price: 0, }, keywords: "" }, // 持续变化跟踪 computed: { book_result() { // const定义的变量不可修改,必须要初始化 const that = this; // 如果输入了关键字 if (this.keywords) { // let是块级作用域,对函数外部无影响 let newBooks = this.books.filter(function(item){ // indexOf查找匹配,若找不到则返回-1 if(item.name.indexOf(that.keywords) != -1){ return true }else{ return false } }); return newBooks // // 在控制台打印出获取到的关键字 // console.log(this.keywords) } else { return this.books } } }, methods: { // 添加图书的方法 add() { // JSON.stringify将JavaScript的值转换成JSON字符串 // JSON.parse将一个JSON字符串转换成对象 let book = JSON.parse(JSON.stringify(this.adding_book)); // 添加date book.date = new Date(); // 将添加的数据加入data中的books列表中去 this.books.push(book); // 添加完成后将输入框内的数据归0 this.adding_book = { name: "", author: "", price: 0, } }, // 删除图书的方法 del(index) { // 从该下标开始删除一个数据 this.books.splice(index, 1) } }, // 过滤器 filters:{ // 将时间格式化 timeFormat:function (value) { value = new Date(value); let year = value.getFullYear(); let month = value.getMonth()+1; let day = value.getDate(); let hour = value.getHours(); let minute = value.getMinutes(); let second = value.getSeconds(); // ``和''的区别 return `${year}-${month}-${day} ${hour}:${minute}:${second}` } } }) </script> </body> </html>

    页面如下:

    Processed: 0.009, SQL: 9