vuejlementtable表格添加行,修改,单独删除行,批量删除行操作

更新时间:2023-06-16 03:13:22 阅读: 评论:0

vuejlementtable表格添加⾏,修改,单独删除⾏,批量删除
⾏操作
1.表格动态添加,也可删除
<template>
<div class="TestWord">
<el-button @click="addLine">添加⾏数</el-button>
<el-button @click="save">保存</el-button>
<el-table
:data="tableData"
>
<el-table-column prop="bookname" label="书名">
<template slot-scope="scope">
<el-input v-model="w.bookname" placeholder="书名"></el-input>
</template>
</el-table-column>
<el-table-column prop="bookvolume" label="册数">
<template slot-scope="scope">
<el-input v-model="w.bookvolume" placeholder="册数"></el-input>
</template>
</el-table-column>
考研报考点能随便选吗<el-table-column prop="bookbuyer" label="购买者">
<template slot-scope="scope">
<el-input v-model="w.bookbuyer" placeholder="购买者"></el-input>
</template>
</el-table-column>
<el-table-column prop="bookborrower" label="借阅者">
<template slot-scope="scope">
<el-input v-model="w.bookborrower" placeholder="借阅者"></el-input>
</template>
</el-table-column>
<el-table-column prop="bookbuytime" label="购买⽇期">
<template slot-scope="scope">
<el-date-picker
v-model="w.bookbuytime"
type="date"
format="yyyy-MM-dd"
value-format="yyyy-MM-dd"
placeholder="购买⽇期">
</el-date-picker>
</template>
</el-table-column>
<el-table-column prop="bookbuytime" label="购买⽇期">
<template slot-scope="scope">
<el-button
size="mini"
type="danger"
v-if="!w.editing"
icon="el-icon-delete"
@click="handleDelete(scope.$index, w)">删除
</el-button>
</template>
</el-table-column>
</el-table>
</div>
</template>
vuejs 代码
export default {
name:'TestWorld',
data() {
return {
tableData:[{
bookname: '',
currybookbuytime: '',
bookbuyer: '',
bookborrower: '',
bookvolume:''
英语教学心得
}]
}
},
methods:{
addLine(){ //添加⾏数
var newValue = {
bookname: '',
bookbuytime: '',
bookbuyer: '',
bookborrower: '',
bookvolume:''
};
//添加新的⾏数
this.tableData.push(newValue);
},
handleDelete(index){ //删除⾏数
this.tableData.splice(index, 1)
},
save(){
//这部分应该是保存提交你添加的内容
console.log(JSON.stringify(this.tableData))
}
}
}
运⾏图⽚
2.编辑表格(即使input已经修改过,当点击取消时,内容不会变)
hurry什么意思<template>
<div class="TestWorld">
<el-button @click="savemodify">保存</el-button>
<el-table
:data="modifyData"
>
<el-table-column prop="bookname" label="书名">
<template slot-scope="scope">
<template v-if="w.editing">
<el-input class="edit-input" v-model="w.bookname" placeholder="书名"></el-input>        </template>
<span v-el>{{ w.bookname }}</span>
</template>
</el-table-column>
<el-table-column prop="bookvolume" label="册数">
kristal
<template slot-scope="scope">
<template v-if="w.editing">
<el-input class="edit-input" v-model="w.bookvolume" placeholder="册数"></el-input>        </template>
<span v-el>{{ w.bookvolume}}</span>
</template>
</el-table-column>蜡笔英语怎么读
<el-table-column prop="bookbuyer" label="购买者">
<template slot-scope="scope">
<template v-if="w.editing">
<el-input class="edit-input" v-model="w.bookbuyer" placeholder="购买者"></el-input>
</template>
<span v-el>{{w.bookbuyer}}</span>
</template>
</el-table-column>
<el-table-column prop="bookborrower" label="借阅者">
<template slot-scope="scope">
<template v-if="w.editing">
<el-input class="edit-input" v-model="w.bookborrower" placeholder="借阅者"></el-input>        </template>
<span v-el>{{w.bookborrower}}</span>
</template>
</el-table-column>
<el-table-column prop="bookbuytime" label="购买⽇期">
<template slot-scope="scope">
<template v-if="w.editing">
<el-date-picker
v-model="w.bookbuytime"
type="date"
value-format="yyyy-MM-dd"
placeholder="购买⽇期">
</el-date-picker>
</template>第二的英文
<span v-el>{{w.bookbuytime}}</span>
</template>
</el-table-column>
<el-table-column prop="editing" label="操作">
<template slot-scope="scope">
ran<el-button
type="danger"
v-if="!w.editing"
icon="el-icon-delete"
v-model="scope.$index"
@click="handleEdit(scope.$index, w)">编辑
</el-button>
<el-button
v-el
type="danger"
icon="el-icon-delete"
v-model="scope.$index"
@click="handleCancle(scope.$index, w)">取消
</el-button>法语词典
</template>
</el-table-column>
</el-table>
</div>
</template>
vuejs 代码
export default {
name:'TestWorld',
data() {
return {
modifyData:[],
prevValue:{}
}
},
mounted(){
},
methods:{
getData(){
this.$ajax({
method: 'get',
url:'../static/json/1.1.1.json', //<---本地地址
//url: '/api/drummer/8bd17859',
}).then((respon)=>{
console.log(JSON.stringify(respon.data))
let _data = respon.data;
let datalength = _data.length;
for(let i = 0;i < datalength; i++){
this.$t(_data[i], 'editing', fal)
}
//赋值
}).catch(function(err){
console.log(err)
})
},
handleEdit(index,row){
row.editing = true;
console.log(index)
this.prevValue = JSON.par(JSON.stringify(row));
},
handleCancle(index,row){
row.editing = fal;
let prevContent = this.prevValue.bookname;
this.$t(row,"bookname",prevContent);
},
savemodify(){
console.log(JSON.difyData))
}
}
}
本地的1.1.1.JSON数据
[{"bookname":"普通⾼等教育物联⽹⼯程专业规划⽤书:物联⽹技术概论","bookbuytime": "2016-05-
04","bookbuyer": "李晓⽉","bookborrower": "王⼩虎","bookvolume":"1"},{"bookname":"区块链⾰命:⽐特币底层技术如何改变货币、商业和世界","bookbuytime": "2016-05-04","bookbuyer": "李晓⽉","bookborrower": "李⼩
虎","bookvolume":"1"},{"bookname":"⼤家⼀起学配⾊:数学⾊彩设计全能书","bookbuytime": "2017-12-
04","bookbuyer": "张晓⽉","bookborrower": "王⽽虎","bookvolume":"1"}]
如果不⽤get本地数据,vuejs如下
export default {
name:'TestWorld',
data() {
return {
modifyData:[
{
bookname: '普通⾼等教育物联⽹⼯程专业规划⽤书:物联⽹技术概论',
bookbuytime: '2016-05-04',
bookbuyer: '李晓⽉',
bookborrower: '王⼩虎',
bookvolume: '1',
editing: fal
},
{
bookname: '区块链⾰命:⽐特币底层技术如何改变货币、商业和世界',
bookbuytime: '2016-05-04',
bookbuyer: '李晓⽉',
bookborrower: '李⼩虎',
bookvolume: '1',
editing: fal
},
{
bookname: '⼤家⼀起学配⾊:数学⾊彩设计全能书',
bookbuytime: '2017-12-04',
bookbuyer: '张晓⽉',
bookborrower: '王⽽虎',
bookvolume: '1',
editing: fal
}
],
prevValue:{}
}
},
methods:{
handleEdit(index,row){ //编辑
row.editing = true;
console.log(index)
this.prevValue = JSON.par(JSON.stringify(row));
},
handleCancle(index,row){ //取消
row.editing = fal;
let prevContent = this.prevValue.bookname;
this.$t(row,"bookname",prevContent);
},
savemodify(){
console.log(JSON.difyData))
}
}
}
运⾏图
3.批量删除⾏数
<template>
<div class="TestWorld">
<el-table ref="multipleTable" :data="tableData3" tooltip-effect="dark"  @lection-change="handleSelectionChange">      <el-table-column type="lection" width="55">
</el-table-column>
<el-table-column label="⽇期" width="120">
<template slot-scope="scope">{{ w.date }}</template>
</el-table-column>
<el-table-column prop="name" label="姓名" width="120">
</el-table-column>
<el-table-column prop="address" label="地址" show-overflow-tooltip>
</el-table-column>
</el-table>
<div >
<el-button @click="batchDelete">批量删除</el-button>
<el-button @click="toggleSelection()">取消选择</el-button>
</div>
</div>
</template>
vuejs 代码
export default {
name:'TestWorld',
data() {
return {
tableData3: [
{
date: '2016-05-03',
航空公司缩写name: '王⼩虎',
address: '上海市普陀区⾦沙江路 1518 弄'
},
{
date: '2016-05-02',
name: '王⼩虎',
address: '上海市普陀区⾦沙江路 1518 弄'
},
{
date: '2016-05-04',
name: '王⼩虎',

本文发布于:2023-06-16 03:13:22,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/90/146592.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:添加   物联   技术   删除   数学   内容   货币   改变
相关文章
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图