请问如何解决 ElementUI 对话框嵌套一个分页表格,切换到其他分页后,之前的分页仍然显示?
问题描述
我在 el-dialog 中嵌套了一个 el-table,且 el-table 还用 el-pagination 做了分页,后端有分页查询的接口,因此我的逻辑是每次切换当前页面索引时,就调用一下分页查询接口,点击 > 按钮切换到下一页之后,前面的页面就作为背景板也显示了,如下图:
问题出现的环境背景及自己尝试过哪些方法
Vue 版本:2.6.10猜想可能是 CSS 的问题,但是我对这方面确实不太精通,实在不知道怎么办才好,跪求大佬指教。
相关代码
主页面
<el-table-column label="权限信息" prop="permission">
<template slot-scope="scope">
<el-dialog title="角色权限信息" :visible.sync="permissionDialogue" width="40%">
<PermissionTable :roleId="scope.row.id"></PermissionTable>
</el-dialog>
<el-button size="mini" slot="reference" @click="permissionDialogue = true">查看</el-button>
</template>
</el-table-column>
PermissionTable.vue
<template>
<div>
<el-card>
<el-table :data="tableData">
<el-table-column label="是否拥有" width="150">
<template slot-scope="scope">
<el-checkbox></el-checkbox>
</template>
</el-table-column>
<el-table-column label="权限ID" prop="id"></el-table-column>
<el-table-column label="权限名" prop="permissionName"></el-table-column>
<el-table-column label="描述" prop="description"></el-table-column>
</el-table>
</el-card>
<div style="text-align: center; margin-top: 10px">
<el-pagination
@size-change="handleSizeChange"
@current-change="handleCurrentChange"
:current-page.sync="currentPage"
:page-sizes="[10, 15, 20]"
:page-size="pageSize"
:total="totalSize"
background
layout="total, sizes, prev, pager, next, jumper">
</el-pagination>
</div>
</div>
</template>
<script>
<template>
<el-card>
<el-table :data="tableData">
<el-table-column label="是否拥有" width="150">
<template slot-scope="scope">
<el-checkbox></el-checkbox>
</template>
</el-table-column>
<el-table-column label="权限ID" prop="id"></el-table-column>
<el-table-column label="权限名" prop="permissionName"></el-table-column>
<el-table-column label="描述" prop="description"></el-table-column>
</el-table>
<div style="text-align: center; margin-top: 10px">
<el-pagination
@size-change="handleSizeChange"
@current-change="handleCurrentChange"
:current-page="currentPage"
:page-size="pageSize"
:total="totalSize"
background
layout="prev, pager, next">
</el-pagination>
</div>
</el-card>
</template>
<script>
import { getPermissionList } from '@/api/auth/permission'
export default {
name: 'PermissionTable',
props: {
roleId: Number
},
data() {
return {
tableData: [],
currentPage: 1,
pageSize: 5,
totalSize: 0
}
},
methods: {
handleCurrentChange(val) {
this.currentPage = val
this.getDataList()
},
handleSizeChange(val) {
this.pageSize = val
this.getDataList()
},
getDataList() {
getPermissionList({
pageNo: this.currentPage,
pageSize: this.pageSize
}).then(res => {
if(res.data.code === 200) {
this.tableData = res.data.pageResult.dataList
this.totalSize = res.data.pageResult.totalCount
} else {
this.$message.error({
message: res.data.message,
duration: 1000
})
}
})
}
},
mounted() {
this.getDataList()
}
}
</script>
回复
1个回答

test
2024-07-01
把el-dialog
写表格外面
// template
<el-table>
<el-table-column label="权限信息" prop="permission">
<template slot-scope="scope">
<el-button size="mini" slot="reference" @click="openPermissionDialog(scope.row.id)">查看</el-button>
</template>
</el-table-column>
<el-table>
<el-dialog title="角色权限信息" :visible.sync="permissionDialogue" width="40%" @closed="closedPermissionDialog">
<PermissionTable :roleId="permissionRoleId"></PermissionTable>
</el-dialog>
// script
data() {
return {
...,
permissionRoleId: null,
}
},
methods: {
openPermissionDialog(id) {
this.permissionRoleId = id;
this.permissionDialogue = true;
},
closedPermissionDialog() {
this.permissionRoleId = null;
},
},
你的permissionDialogue
是一个,所以是用一个弹窗展示当前点击行的详情,不能把el-dialog
写在el-table-column
里,这样你是每行会都有一个弹窗,假设列表有10行,按你的写法点一个查看,会同时打开10个弹窗,也就有10个分页,你只能操作切换最上层的翻页,下面的弹窗当然不会变,下面的背景也不应该存在。
回复

适合作为回答的
- 经过验证的有效解决办法
- 自己的经验指引,对解决问题有帮助
- 遵循 Markdown 语法排版,代码语义正确
不该作为回答的
- 询问内容细节或回复楼层
- 与题目无关的内容
- “赞”“顶”“同问”“看手册”“解决了没”等毫无意义的内容