在el-dailog里面使用el-select和el-date-picker位置错乱问题

文章讲述了在el-dialog组件中,el-select和el-date-picker选择下拉框可能出现的位置错乱问题,通过添加特定class、设置append-to-body属性以及调整scopedstyle来修复这一问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在el-dialog里面使用el-select和el-date-picker有时会发生选择下拉框位置错乱,跑到其他地方去了,根据网上搜索的参考内容整理记录一下

一、el-select相关

解决:1、在外部el-dialog或其他div标签添加class

        <el-dialog class="settle-dialog"></el-dialog >

        2、在el-select里面添加:append-to-body="false"属性,如果不添加的话,我们查看元素会发现下拉框所在的div和el-select是不同级的,是在最外面,添加以后就可以在el-select的子级元素中看到了

        <el-select :popper-append-to-body="false"></el-select>

        3、在写有scoped的style标签里修改下拉框的样式

        .settle-dialog ::v-deep .el-select-dropdown {

                  position: absolute !important;

        }

二、el-date-picker相关

解决:1、同上类似 给el-date-picker标签添加属性:append-to-body="false"

        2、在el-date-picker标签添加一个class, popper-class="time-date-picker"

        <el-date-picker  :append-to-body="false" popper-class="time-date-picker"></el-date-picker>

        3、在style里面修改样式

        ::v-deep .time-date-picker {

                  position: absolute !important;

        }

参考地址:el-select下拉框位置错乱(在el-dialog中使用)-优快云博客

        https://www.cnblogs.com/xb130460/p/14688185.html

``` <div class="box_search"> <div style="margin-top: 20px"> <el-date-picker v-model="createTime" value-format="yyyy-MM-dd" type="daterange" align="right" unlink-panels range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" :picker-options="pickerOptions"> </el-date-picker> </div> <div style="margin-left: 20px;margin-top: 20px"> <el-input style="width: 200px" v-model="mailNo" :clearable="true" placeholder="运单编号"></el-input> <el-input style="margin-left: 20px;width: 260px" :clearable="true" v-model="keywords" placeholder="收件人姓名/收件人电话/收件地址"></el-input> <el-select style="margin-left: 20px" v-model="express_cate" placeholder="快递类型" > <el-option v-for="(express,index) in express_list" :key="index" :label= "express.name" :value="express.cate_id"> </el-option> </el-select> <el-select style="margin-left: 20px" v-model="input3" placeholder="全部-渠道" > <el-option :label= "'全部-渠道'" :value="0"> </el-option> </el-select> <el-button type="primary" style="margin-left: 10px" @click="getList"> 查询</el-button> <el-button type="primary" @click="handleExport">导出筛选数据</el-button> </div> </div>.box_search{ margin-left: 20px; width: 100%; display: flex; /*justify-content: space-between;*/ }```现在问题是窗口缩小后按钮位置会乱,要求是窗口缩小后位置不要乱,窗口缩小后全可以看到,不要复杂的,根据我的代码,帮我修改下,不要重新写新的代码,不想换行,还是原来的位置
03-18
``` <div style=" float: left; width: 50%; height: 500px;background-color: white;border-radius: 10px ;margin-top: 10px "> <div style="width: 5px;height: 25px;background-color: #1f78ff;margin-top: 22px;margin-left: 10px;border-radius: 10px;float: left"> </div> <div style="float: left;margin-left: 10px;margin-top: 20px;font-size: 20px;font-weight: bold"> 今日有效单量:{{ userinfo.today_order || '0' }}单 </div> <div style="float: right;font-size: 14px;color: gray;padding-top: 20px;padding-right: 20px">更新时间:{{ userinfo.nowtime }} <button @click="showdrawer" type="primary" style="color: rgb(64,158,255);background-color: white;border: none">数据表格 ></button> </div> <div style="clear: both"></div> <div style="float: left;margin-left: 8px;margin-top: 10px"> 日期A:<span style="color: rgb(64,158,255);font-weight: bold">{{ this.totalBa }}</span>单 日期B:<span style="color: rgb(64,158,255);font-weight: bold">{{ this.totalAa }}</span>单 升幅: <span style="font-weight: bold">{{ this.totalBa - this.totalAa }}</span>单</div> <div style="clear: both"></div> <div style="float: left;margin-left: 8px;padding-top: 20px"> 对比日期A: </div> <div style="clear: both"></div> <div style="float: left;margin-left: 106px;margin-top: -26px"> <el-date-picker value-format="yyyy-MM-dd" style="width: 140px;" v-model="timeA" type="date" @change="getOrderChart" placeholder="选择日期"> </el-date-picker> </div> <div style="clear: both"></div> <div style="float: left;margin-left: 260px;margin-top: -32px"> 对比日期B: </div> <div style="clear: both"></div> <div style="float: left;margin-left: 360px;margin-top: -36px"> <el-date-picker value-format="yyyy-MM-dd" style="width: 150px;" v-model="timeB" type="date" @change="getOrderChart" placeholder="选择日期"> </el-date-picker> </div> <div style="margin-top: -36px;float: right;margin-right: 150px"> <el-select style="width: 120px" v-model="current_time" placeholder="当前对比" @change="getOrderChart"> <el-option v-for="item in option_time" :label=item.label :value="item.value"> </el-option> </el-select> </div> </div> <div style="clear: both"></div> <div style="background-color: #FFFFFF;float: right;sborder-radius: 10px;margin-top: -29%;width: 30%"> <div style="width: 5px;height: 25px;background-color: #1f78ff;margin-top: 32px;margin-left: 10px;border-radius: 10px;float: left"> </div> <div style="float: left;margin-left: 10px;margin-top: 30px;font-size: 20px;font-weight: bold"> 我的寄件数量 </div> <div style="clear: both"></div> <div style="float: left;margin-top: 20px;font-size: 14px;color: gray;padding-left: 10px"> 更新时间:{{ userinfo.nowtime }} </div> <div style="clear: both"></div> <div ref="chinaMap" style="width: 600px; height: 400px;background-color: white"> </div> <div style="clear: both"></div> <div style="float: right;margin-top:-470px;margin-right: 30px"> <el-radio-group v-model="radio1"> <el-radio-button label="今日"></el-radio-button> <el-radio-button label="昨日"></el-radio-button> <el-radio-button label="本周"></el-radio-button> </el-radio-group> </div> </div>```<div style="margin-top: -36px;float: right;margin-right: 150px"> <el-select style="width: 120px" v-model="current_time" placeholder="当前对比" @change="getOrderChart"> <el-option v-for="item in option_time" :label=item.label :value="item.value"> </el-option> </el-select> </div> <div style="background-color: #FFFFFF;float: right;sborder-radius: 10px;margin-top: -29%;width: 30%">窗口缩小后这俩块地方位置错乱,要求在我的代码基础上改动
03-20
``` <div style="width: 110%;height: 220%;background-color: white;float: left;margin-top: 40px;margin-left: -660px;border-radius: 10px"> <div style="width: 5px;height: 25px;background-color: #1f78ff;margin-top: 22px;margin-left: 10px;border-radius: 10px;float: left"> </div> <div style="float: left;margin-top: 20px;font-size: 20px;font-weight: bold;width: 40%;"> 今日有效单量:{{ userinfo.today_order || '0' }}单 </div> <div style=" float: right;font-size: 14px;color: gray;padding-top: 20px;padding-right: 20px">更新时间:{{ userinfo.nowtime }} <button @click="showdrawer" type="primary" style="color: rgb(64,158,255);background-color: white;border: none">数据表格 ></button> </div> <div style="clear: both"></div> <div style="float: left;padding-top: 10px;padding-left: 10px;"> 日期A:<span style="color: rgb(64,158,255);font-weight: bold">{{ this.totalBa }}</span>单 日期B:<span style="color: rgb(64,158,255);font-weight: bold">{{ this.totalAa }}</span>单 升幅: <span style="font-weight: bold">{{ this.totalBa - this.totalAa }}</span>单 </div> <div style="clear: both"></div> <div style="float: left;padding-left: 8px;padding-top: 20px"> 对比日期A: </div> <div style="clear: both"></div> <div style="float: left;margin-left: 106px;margin-top: -26px"> <el-date-picker value-format="yyyy-MM-dd" style="width: 140px;" v-model="timeA" type="date" @change="getOrderChart" placeholder="选择日期"> </el-date-picker> </div> <div style="clear: both"></div> <div style="float: left;padding-left: 260px;margin-top: -32px;"> 对比日期B: </div> <div style="clear: both"></div> <div style="float: left;padding-left: 360px;margin-top: -36px;"> <el-date-picker value-format="yyyy-MM-dd" style="width: 150px;" v-model="timeB" type="date" @change="getOrderChart" placeholder="选择日期"> </el-date-picker> </div> <div style="float: right;margin-top: -36px;margin-right: 350px;"> <el-select style="width: 50%;" v-model="current_time" placeholder="当前对比" @change="getOrderChart"> <el-option v-for="item in option_time" :label=item.label :value="item.value "> </el-option> </el-select> </div> <div style="clear: both"></div> </div>```窗口缩小里面的今日有效单量:0单日期A:0单 日期B:0单 升幅: 0单 2025-03-16 对比日期B: 2025-03-17 当前对比 位置发生错乱看不到了,要求是不要新代码在我的代码基础上修改,达到窗口缩小后依然全可以看到
03-18
``` <div style="width: 110%;height: 220%;background-color: white;float: left;margin-top: 40px;margin-left: -660px;border-radius: 10px"> <div style="width: 5px;height: 25px;background-color: #1f78ff;margin-top: 22px;margin-left: 10px;border-radius: 10px;float: left"> </div> <div style="float: left;margin-top: 20px;font-size: 20px;font-weight: bold;width: 40%;"> 今日有效单量:{{ userinfo.today_order || '0' }}单 </div> <div style="float: right;font-size: 14px;color: gray;padding-top: 20px;padding-right: 20px">更新时间:{{ userinfo.nowtime }} <button @click="showdrawer" type="primary" style="color: rgb(64,158,255);background-color: white;border: none">数据表格 ></button> </div> <div style="clear: both"></div> <div style="float: left;margin-left: 8px;margin-top: 10px"> 日期A:<span style="color: rgb(64,158,255);font-weight: bold">{{ this.totalBa }}</span>单 日期B:<span style="color: rgb(64,158,255);font-weight: bold">{{ this.totalAa }}</span>单 升幅: <span style="font-weight: bold">{{ this.totalBa - this.totalAa }}</span>单</div> <div style="clear: both"></div> <div style="float: left;margin-left: 8px;padding-top: 20px"> 对比日期A: </div> <div style="clear: both"></div> <div style="float: left;margin-left: 106px;margin-top: -26px"> <el-date-picker value-format="yyyy-MM-dd" style="width: 140px;" v-model="timeA" type="date" @change="getOrderChart" placeholder="选择日期"> </el-date-picker> </div> <div style="clear: both"></div> <div style="float: left;margin-left: 260px;margin-top: -32px;position: relative"> 对比日期B: </div> <div style="clear: both"></div> <div style="float: left;margin-left: 360px;margin-top: -36px;position: relative"> <el-date-picker value-format="yyyy-MM-dd" style="width: 150px;" v-model="timeB" type="date" @change="getOrderChart" placeholder="选择日期"> </el-date-picker> </div> <div style="clear: both"></div> <div style="float: right;margin-top: -36px;margin-right: 440px;position: relative"> <el-select style="width: 120px;position: relative" v-model="current_time" placeholder="当前对比" @change="getOrderChart"> <el-option v-for="item in option_time" :label=item.label :value="item.value"> </el-option> </el-select> </div> <div style="clear: both"></div> </div>```窗口缩小后里面位置发生错乱怎么解决
03-15
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值