本文執行個體為大家分享了Vue.js實作可編輯的表格的具體代碼,供大家參考,具體内容如下
table tr td{
text-align: center;
}
.btn-info{
margin-left: 5px;
}
.add,.addBox{
margin: 10px 0px 10px 10px;
}
.submit{
margin-left: 172px;
}
.delAll{
margin-left: 10px;
}
fieldset{
margin-left: 10px;
}
添加
批量删除
學号姓名年紀操作
{{person.sid}}{{person.sname}}{{person.sage}}删除編輯
新增使用者
學号:
姓名:
年齡:
送出
編輯使用者
學号:
姓名:
年齡:
送出
var data ={
people:[
{"sid":"1043","sname":"張三","sage":18},
{"sid":"2434","sname":"趙六","sage":43},
{"sid":"3424","sname":"李四","sage":42},
{"sid":"1231","sname":"王五","sage":35}
],
newPeople:{
"sid":"","sname":"","sage":""
},
seen:false,
editSeen:false,
checked:false,
selected:[],
editPeople:{
"sid":"","sname":"","sage":""
}
} ;
var app = new Vue({
"el":"#app",
data:data,
methods:{
// 添加
addBox:function(){
this.seen = this.seen == false ? true : false;
},
//删除
del:function(index){
console.log(11);
this.people.splice(index,1);
},
//送出
add:function(){
//插入到people中
this.people.push(this.newPeople);
this.newPeople = {};
this.seen = false
},
//全選
allSelect:function(){
if(this.selected.length != this.people.length){
this.selected = [];
for(var i = 0; i
this.selected.push(this.people[i].sid);
console.log(this.people[i].sid);
}
}else{
this.selected = [];
}
},
//批量删除
delAll:function(){
for(var j = 0; j< this.selected.length;j++){
for(var i = 0; i< this.people.length; i++){
if(this.selected[j] == this.people[i].sid){
this.people.splice(i,1);
}
}
}
},
//編輯
update:function(index){
this.editSeen = true;
this.editPeople = this.people[index];
},
//編輯後送出
editSubmit:function(){
this.editSeen = false;
}
},
watch:{
"selected":function(){
if(this.selected.length == this.people.length){
this.checked = true;
}else{
this.checked = false;
}
}
}
})
以上就是本文的全部内容,希望對大家的學習有所幫助,也希望大家多多支援雲海天教程。