Vue+Element实时局部刷新表格某一行的样式和属性值(带源码)
element
A Vue.js 2.0 UI Toolkit for Web
项目地址:https://gitcode.com/gh_mirrors/eleme/element
免费下载资源
·
使用场景分析,要求提交数据表中修改的某行数据,实时刷新该行数据的状态,该行的某条属性是根据条件渲染的。
el-table部分:
<el-table-column label="关联状态" width="100">
<template slot-scope="scope">
<el-tag
:type="scope.row.status === 'true' ? 'success' : 'info'"
disable-transitions>{{scope.row.status === 'true' ? '显示' : '禁止'}}
</el-tag>
</template>
</el-table-column>
js部分
//手动改变表单值
this.tableData[index].tag = !this.tableData[index].tag
//利用vue的$set方法进行更新表格数据
this.$set(this.tableData, index, row);
源码部分
<template>
<div>
<div v-show="tableShow" class="reltable">
<el-table ref="filterTable" :data="tableData" style="width: 100%;">
<el-table-column
prop="date"
label="日期"
sortable
width="180"
column-key="date"
>
</el-table-column>
<el-table-column prop="name" label="姓名" width="180">
</el-table-column>
<el-table-column prop="address" label="地址" :formatter="formatter">
</el-table-column>
<el-table-column prop="tag" label="标签" width="100">
<template slot-scope="scope">
<el-tag
:type="scope.row.tag === 'true' ? 'success' : 'info'"
disable-transitions
>{{scope.row.tag==='true' ? '家':'公司'}}</el-tag
>
</template>
</el-table-column>
<el-table-column label="操作">
<template slot-scope="scope">
<el-button
size="mini"
@click="handleEdit(scope.$index, scope.row)"
>编辑</el-button
>
<el-button
size="mini"
type="danger"
@click="handleDelete(scope.$index, scope.row)"
>删除</el-button
>
</template>
</el-table-column>
</el-table>
</div>
</div>
</template>
<script>
export default {
name: 'Table',
data() {
return {
tableShow: false,
tableData: [
{
date: '2016-05-03',
name: '王小虎',
address: '上海市普陀区金沙江路 1518 弄',
},
{
date: '2016-05-02',
name: '王小虎',
address: '上海市普陀区金沙江路 1518 弄',
tag: 'false',
},
{
date: '2016-05-04',
name: '王小虎',
address: '上海市普陀区金沙江路 1518 弄',
tag: 'true',
},
{
date: '2016-05-01',
name: '王小虎',
address: '上海市普陀区金沙江路 1518 弄',
tag: 'false',
},
{
date: '2016-05-08',
name: '王小虎',
address: '上海市普陀区金沙江路 1518 弄',
tag: 'true',
},
{
date: '2016-05-06',
name: '王小虎',
address: '上海市普陀区金沙江路 1518 弄',
tag: 'false',
},
{
date: '2016-05-07',
name: '王小虎',
address: '上海市普陀区金沙江路 1518 弄',
tag: 'true',
},
],
}
},
created: function () {},
methods: {
handleEdit(index, row) {
this.tableData[index].tag = !this.tableData[index].tag;
this.$set(this.tableData, index, row);
console.log(index, row)
},
handleDelete(index, row) {
console.log(index, row)
},
},
}
</script>
<style scoped></style>
GitHub 加速计划 / eleme / element
54.06 K
14.63 K
下载
A Vue.js 2.0 UI Toolkit for Web
最近提交(Master分支:3 个月前 )
c345bb45
7 个月前
a07f3a59
* Update transition.md
* Update table.md
* Update transition.md
* Update table.md
* Update transition.md
* Update table.md
* Update table.md
* Update transition.md
* Update popover.md 7 个月前
更多推荐
已为社区贡献1条内容
所有评论(0)