基于Vue實現(xiàn)圖書管理功能
更新時間:2017年10月17日 14:49:30 作者:damys
這篇文章主要為大家詳細(xì)介紹了基于Vue實現(xiàn)圖書管理功能,具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文實例為大家分享了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í)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
useEffect理解React、Vue設(shè)計理念的不同
這篇文章主要為大家介紹了useEffect理解React、Vue設(shè)計理念的不同詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-09-09vue的表單數(shù)據(jù)收集案例之基本指令和自定義指令詳解
收集表單數(shù)據(jù)可以使用這個v-model實現(xiàn)這個數(shù)據(jù)的綁定,但是在有些輸入框中,還需要一些其他的指令搭配這個v-model指令結(jié)合使用,這篇文章主要介紹了vue的表單數(shù)據(jù)收集,基本指令和自定義指令,需要的朋友可以參考下2023-01-01vue子組件實時獲取父組件的數(shù)據(jù)實現(xiàn)
本文主要介紹了vue子組件實時獲取父組件的數(shù)據(jù)實現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2023-12-12詳解Vue一個案例引發(fā)「內(nèi)容分發(fā)slot」的最全總結(jié)
這篇文章主要介紹了詳解Vue一個案例引發(fā)「內(nèi)容分發(fā)slot」的最全總結(jié),小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-12-12