国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

基于Vue實現(xiàn)圖書管理功能

2019-11-19 15:09:16
字體:
供稿:網(wǎng)友

本文實例為大家分享了vue簡單的圖書管理具體代碼,供大家參考,具體內(nèi)容如下

<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('確認(rèn)要刪除?')){    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>

效果圖:

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持武林網(wǎng)。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 奉贤区| 随州市| 富裕县| 海伦市| 兴业县| 叙永县| 都江堰市| 隆子县| 丰都县| 沧州市| 泰兴市| 保康县| 双柏县| 哈巴河县| 湘阴县| 鹰潭市| 哈密市| 鸡泽县| 花莲县| 潜江市| 中西区| 北辰区| 隆林| 望谟县| 邢台县| 万载县| 眉山市| 信宜市| 兰坪| 石林| 洛宁县| 焉耆| 江达县| 高密市| 乌海市| 永善县| 宜宾市| 四子王旗| 谷城县| 资阳市| 福海县|