基于Vue实现图书管理功能
2017-10-17 14:49
776 查看
本文实例为大家分享了vue简单的图书管理具体代码,供大家参考,具体内容如下
<table class="table table-bg table-border table-bordered"> <tr> <th>ID</th> <th>书名</th> <th>作者</th> <th>价格</th> <th>操作</th> </tr> <tr v-for="(book,index) in books"> <td>{{book.id}}</td> <td>{{book.name}}</td> <td>{{book.author}}</td> <td>{{book.price}}</td> <td> <button class="btn" @click="delBook(index)">删除</button> </td> </tr> </table> <fieldset> <legend>添加新书</legend> <p>书名:<input type="text" v-model="newBook.name"></p> <p>作者:<input type="text" v-model="newBook.author"></p> <p>价格:<input type="text" v-model="newBook.price"></p> <p><button class="btn" @click="addBook">添加</button></p> </fieldset> <script> new Vue({ el:'#books', data:{ books:[ {id:1, name:'红楼梦', author:'曹雪芹', price:'1'}, {id:2, name:'西游记', author:'吴承恩', price:'2'}, {id:3, name:'水浒传', author:'施耐庵', price:'3'} ], newBook:{ id:0, name:'', author:'', price:'' } }, methods:{ delBook:function(idx){ if(window.confirm('确认要删除?')){ this.books.splice(idx, 1); } }, addBook:function(){ // 约束 if(this.newBook.name.length == 0) { alert('书名不能为空'); return; } if(this.newBook.author.length == 0){ alert('书的作者不能为空'); return; } if(this.newBook.price.length == 0){ this.newBook.price = '0' } // 计算插入id var maxId = 0; for(var i=0; i<this.books.length; i++){ if(maxId<this.books[i].id){ maxId = this.books[i].id; } } this.newBook.id = maxId+1; // 插入到 books中 this.books.push(this.newBook); // 清空新书 this.newBook = {}; } } }); </script>
效果图:
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。
您可能感兴趣的文章:
相关文章推荐
- 数字天堂HBuilder+MUI(五)基于native.js的文件系统管理功能实现
- 图书管理系统1---登录功能实现
- vue实现图书管理demo详解
- 基于Vue实现tab栏切换内容不断实时刷新数据功能
- 基于JAVA的图书数据库管理-具有新增,修改,删除,查询功能
- 【CSDN开源夏令营】 基于Web的SSH客户端,实现跨平台的云服务管理(三)远程登录功能的实现
- 基于vue-simplemde实现图片拖拽、粘贴功能
- 利用java实现基于文本的图书管理系统(有界面)
- 基于C语言的图书管理信息系统的设计与实现
- Winform开发框架之参数配置管理功能实现-基于SettingsProvider.net的构建
- 微信小程序开发日志2018-03-04: 实现图书管理小程序基本功能
- 基于.NET平台的Windows编程实战(六)—— 题目管理功能的实现
- Vue + Element UI 实现权限管理系统 前端篇(七):功能组件封装
- 基于.NET平台的Windows编程实战(六)—— 题目管理功能的实现
- 基于vue+ bootstrap实现图片上传图片展示功能
- 艾伟_转载:基于.NET平台的Windows编程实战(六)—— 题目管理功能的实现
- 图书管理系统(增,改,删,查)功能的实现
- Android app基于DownloadProvider实现下载管理功能
- 【CSDN开源夏令营】 基于Web的SSH客户端,实现跨平台的云服务管理(四)文件树功能的实现
- 基于RFID的简易图书管理系统设计与实现