没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论















基于基于Vue实现图书管理功能实现图书管理功能
主要为大家详细介绍了基于Vue实现图书管理功能,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
本文实例为大家分享了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;
}
}
资源评论


weixin_38573171
- 粉丝: 7
- 资源: 945
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助


安全验证
文档复制为VIP权益,开通VIP直接复制
