vue基于bootstrap制作動態(tài)表格添加刪除行列表和編輯修改行內(nèi)容效果代碼。
使用方法:
1、head引入css文件
<link rel="stylesheet" href="css/bootstrap.min.css"/>
2、head引入js文件
<script src="js/jquery-1.7.2.min.js"></script>
<script src="js/bootstrap.js"></script>
<script src="js/vue.js"></script>
<script>
window.onload = function(){
new Vue({
el:'#box',
data:{
myData:[],
nowIndex:-100
},
methods:{
add:function(){
this.myData.push({
})
},
del:function(n){
if(n ==-2){
this.myData="";
}else{
this.myData.splice(n,1);
}
}
}
})
}
</script>
3、body引入部分
<div class="container" id="box">
<table class="table table-bordered table-hover">
<caption class="h3 text-info">布料詳細(xì)表</caption>
<tr>
<th class="text-center" style="width: 5%;">序號</th>
<th class="text-center" style="width: 55%;">布類</th>
<th class="text-center" style="width: 10%;">克重</th>
<th class="text-center" style="width: 10%;">單位</th>
<th class="text-center" style="width: 10%;">單價</th>
<th class="text-center"><input type="button" value="+" class="btn btn-primary" v-on:click="add()"/></th>
</tr>
<tr class="text-center" v-for="item in myData">
<td>{{$index+1}}</td>
<td>
<select id="fab" name="fab" style="width:90%">
<option value="1">30s/1 精梳棉 疋染 1x1 羅紋布 (正常整理)</option>
<option value="2">32s/1 精梳棉 + 70D 彈性纖維 疋染凈色 1x1 羅紋布 (正常整理)</option>
<option value="3">32s/1x2 CVC 60/40 疋染 抓毛位衣 (磨毛(面))</option>
<option value="4">32s/1 CVC 60/40 疋染 平紋布 (正常整理)</option>
<option value="5">26s/1 精梳棉 疋染凈色 1x1 羅紋布 (蝕毛)</option>
<option value="6">20s/1x3 精梳棉 疋染 扁機(jī)領(lǐng)(ottoman) (正常整理)</option>
</select>
</td>
<td>
<input type="text" id="weight" name="weight" style="width:90%"/>
</td>
<td>
<input type="text" id="unit" name="unit" style="width:90%"/>
</td>
<td>
<input type="text" id="price" name="peice" style="width:45%"/>
</td>
<td>
<button class="btn btn-del btn-sm" data-toggle="modal" data-target="#layer" v-on:click="nowIndex=$index">X</button>
</td>
</tr>
<tr v-show="myData.length==0">
<td colspan="6" class="text-center text-info">
<p>暫無數(shù)據(jù)...</p>
</td>
</tr>
</table>
<!--彈出框-->
<div role="dialog" class="modal fade" id="layer" data-index="{{nowIndex}}">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button class="close" data-dismiss="modal">
<span>×</span>
</button>
<h4 class="modal-title">確認(rèn)刪除嗎?</h4>
</div>
<div class="modal-body text-right">
<button class="btn btn-cancel btn-sm" data-dismiss="modal">取消</button>
<button class="btn btn-danger btn-sm" data-dismiss="modal" v-on:click="del(nowIndex)">確認(rèn)</button>
</div>
</div>
</div>
</div>
</div>