Vue - 关于el-dialog 会让body 标签内的滚动条隐藏,导致窗口抖动的问题 和双滚动条问题

文章主要介绍了在使用Element-UI的el-dialog组件时遇到的body滚动条隐藏导致窗口抖动以及双滚动条问题。通过设置`:lock-scroll`和`:append-to-body`属性为`false`可以解决抖动问题,而添加CSS样式如`overflow-y:scroll!important`和调整布局可以消除双滚动条。解决方案还引用了相关的参考链接。
摘要由CSDN通过智能技术生成

问题:

关于el-dialog 会让body 标签内的滚动条隐藏,导致窗口抖动的问题

抖动问题

抖动问题就不演示了,很简单,按如下配置就能解决:
在这里插入图片描述

双滚动条问题演示:

在这里插入图片描述

双滚动条解决效果演示:

在这里插入图片描述

解决方法:

笔者在这里解决这两种问题的解决方法如下:(注意笔者这里是两个问题一起先后出现的)

1、 解决窗口抖动问题

<el-dialog
  :title="formTitle"
  :visible.sync="dialogFormVisible"
  :lock-scroll="false"  //主要是这个属性
  :append-to-body="true"   //跟这个属性
  :close-on-click-modal="false"
>
</el-dialog>

2、解决双滚动条问题

overflow-y: scroll !important; //主要是这个属性

.el-dialog {
  display: flex !important;
  flex-direction: column !important;
  margin: 0 !important;
  position: absolute !important;
  top: 50% !important;
  left: 50% !important;
  transform: translate(-50%, -50%) !important;
  overflow-y: scroll !important;
  max-height: 99vh !important;
}

参考链接

1. Element-UI模态框会话框弹框dialog出现滚动条,再次点击无法置顶滚动条的解决方法

2. ialog弹出,点确定,页面隐藏滚动条,导致页面和message弹框抖动

3. element-plus:el-Dialog对话框组件垂直居中、禁止屏幕滚动、使用内滚动

  • 5
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在el-dialog下打印带滚动条el-table,可以使用vue-print-nb插件结合一些CSS样式来实现。 首先,在el-dialog的模板中,给el-table和el-dialog添加一个唯一的id属性: ``` html <el-dialog title="打印内容" :visible.sync="dialogVisible" :close-on-click-modal="false"> <div id="printArea"> <el-table id="printTable" :data="tableData" style="width: 100%" height="300"> <el-table-column prop="name" label="姓名" width="180"></el-table-column> <el-table-column prop="age" label="年龄" width="180"></el-table-column> <el-table-column prop="address" label="地址"></el-table-column> </el-table> </div> </el-dialog> ``` 接着,在打印按钮的点击事件中,使用vue-print-nb插件的print方法,并添加一些CSS样式: ``` javascript import Vue from 'vue' import VuePrintNB from 'vue-print-nb' Vue.use(VuePrintNB) export default { data() { return { dialogVisible: false, tableData: [ { name: '张三', age: 18, address: '北京市朝阳区' }, { name: '李四', age: 22, address: '上海市浦东新区' }, { name: '王五', age: 30, address: '广州市天河区' } ] } }, methods: { handlePrint() { // 打印内容 const printContent = document.getElementById('printArea').innerHTML // 打印配置 const printConfig = { title: '', footer: '', style: ` #printTable { width: 100%; } #printTable .cell { padding: 10px; font-size: 14px; text-align: center; border: 1px solid #ddd; } #printTable .cell .cell { padding: 0; text-align: left; } #printTable .cell.el-tooltip { display: none; } #printTable .cell .cell { padding: 0; text-align: left; } #printTable .cell .cell .cell { padding: 0; } #printTable .cell .cell .cell .cell { padding: 0; } #printTable .cell .cell .cell .cell .cell { padding: 0; } #printTable .cell .cell .cell .cell .cell .cell { padding: 0; } #printArea { height: auto !important; } ` } // 使用vue-print-nb插件的print方法打印 this.$print(printContent, printConfig) } } } ``` 在CSS样式中,需要设置打印的表格宽度为100%,并给表格的单元格添加一些样式,以保证打印出来的表格的格式正确。 另外,由于el-table在el-dialog中带有滚动条,所以还需要设置打印内容的高度为自动(height: auto !important),以保证打印出来的内容可以完整显示。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值