相關(guān)版實例代碼如下:
馬鞍山網(wǎng)站制作公司哪家好,找成都創(chuàng)新互聯(lián)公司!從網(wǎng)頁設(shè)計、網(wǎng)站建設(shè)、微信開發(fā)、APP開發(fā)、響應(yīng)式網(wǎng)站建設(shè)等網(wǎng)站項目制作,到程序開發(fā),運營維護。成都創(chuàng)新互聯(lián)公司公司2013年成立到現(xiàn)在10年的時間,我們擁有了豐富的建站經(jīng)驗和運維經(jīng)驗,來保證我們的工作的順利進行。專注于網(wǎng)站建設(shè)就選成都創(chuàng)新互聯(lián)公司。
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>vue實例:添加刪除元素r</title> <style type="text/css"> .form-group{ margin:10px; } .form-group>label{ display: inline-block; width: 5rem; text-align: right; } </style> </head> <body> <div id="app"> <div class="form-group"> <label>name:</label> <input type="text" name="" v-model='newitems.name'> </div> <div class="form-group"> <label>age:</label> <input type="text" name="" v-model='newitems.age'> </div> <div class="form-group"> <label>sex:</label> <select v-model='newitems.sex'> <option value="男">男</option> <option value="女">女</option> </select> </div> <div class="form-group"> <label></label> <button v-on:click = 'addPerson'>Create</button> </div> <table> <thead> <tr> <th>Name</th> <th>Age</th> <th>Sex</th> <th>Delete</th> </tr> </thead> <tbody> <tr v-for="item in items"><!--v-for--> <td>{{item.name}}</td> <td>{{item.age}}</td> <td>{{item.sex}}</td> <td><button @click="deletePerson($index)">Delete</button></td> </tr> </tbody> </table> </div> </body> <script src="vue.js"></script> <script type="text/javascript"> var vm = new Vue({ el:'#app', data:{ newitems:{ name:'', age:'18', sex:'女' },//newitems默認的 items:[{ name:'lily', age:18, sex:'女' },{ name:'lily', age:18, sex:'女' },{ name:'lily', age:18, sex:'女' },{ name:'lily', age:18, sex:'女' },{ name:'lily', age:18, sex:'女' }] }, methods:{ addPerson:function(){ this.items.push(this.newitems)//往items中添加newitems this.newitems = {name:'',age:'18',sex:'女'} },//添加元素 deletePerson: function(index){ // 刪一個數(shù)組元素 this.items.splice(index,1); } } }) </script> </html>
大家可以測試以下,感謝大家對創(chuàng)新互聯(lián)的支持。
新聞名稱:詳解vue添加刪除元素的方法
當前鏈接:http://www.muchs.cn/article0/gjgpoo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供Google、網(wǎng)站內(nèi)鏈、云服務(wù)器、動態(tài)網(wǎng)站、品牌網(wǎng)站制作、域名注冊
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)