Element组件,el-select下拉框选择,将PC端与移动端共用一个界面,会导致option宽度异常,且居左隐藏了部分下拉框数据,解决办法如下:
其他方法没有粘上来,需要修改:
1、<template>块:
<el-row justify="center" align="middle">
<el-col :xs="24" :sm="20" :md="20" :lg="18" :xl="18">
<el-select
v-model="searchValue"
placeholder="请输入搜索关键字"
filterable
remote
autofocus
:trigger-on-focus="false"
:remote-method="remoteMethod"
:loading="loading"
@change="handleSelect"
@focus="setOptionWidth"
:popper-append-to-body="false"
popper-class="music-el-select"
:style="{ display: 'block' }"
>
<el-option
v-for="item in options"
:key="item.value"
:label="item.label"
:value="item.value"
:style="{
width: selectOptionWidth
}"
></el-option>
</el-select>
</el-col>
</el-row>
2、<script>块:
export default {
name: 'Test',
data() {
return {
selectOptionWidth: '',
}
},
methods: {
setOptionWidth(event) {
// 下拉框聚焦,设置弹框的宽度
this.$nextTick(() => {
this.selectOptionWidth = event.srcElement.offsetWidth + 'px';
});
}
}
};
3、<style>块:
<style lang="less" scoped>
/deep/ .music-el-select {
left: 0 !important;
}
</style>