fix: 下拉组件选项宽度无限宽

This commit is contained in:
fit2cloud-chenyw 2021-10-14 14:41:28 +08:00
parent c274aece5b
commit 74ec45a458

View File

@ -10,13 +10,17 @@
:placeholder="$t(options.attrs.placeholder)"
:popper-append-to-body="inScreen"
@change="changeValue"
@focus="setOptionWidth"
>
<el-option
v-for="item in options.attrs.datas"
:key="item[options.attrs.key]"
:style="{width:selectOptionWidth}"
:label="item[options.attrs.label]"
:value="item[options.attrs.value]"
/>
>
<span :title="item[options.attrs.label]" style="display:inline-block;width:100%;white-space:nowrap;text-overflow:ellipsis;overflow:hidden;">{{ item[options.attrs.label] }}</span>
</el-option>
</el-select>
</template>
@ -43,7 +47,8 @@ export default {
data() {
return {
options: null,
showNumber: false
showNumber: false,
selectOptionWidth: 0
}
},
computed: {
@ -119,6 +124,12 @@ export default {
text: item
}
})
},
setOptionWidth(event) {
//
this.$nextTick(() => {
this.selectOptionWidth = event.srcElement.offsetWidth + 'px'
})
}
}