Existing Component
Yes
Component Name
el-select
Description
I have an object that I want to set as default value for el-select.
There is a prop "value-key" that determines which field from the object to treat as a key. But it's also used as a label in this case.
How to set a "value-label" so the select's input displays custom label rather then the value of the key?
I use the below "hack" which is not really reliable:
this.$nextTick(() => {
let label = object[this.labelKey]
let elem = this.$refs.selectElem
elem.selectedLabel = label
})
What is the correct way to accomplish that?
3条答案
按热度按时间yzckvree1#
You need to add the object into the candidates array that used for
el-option
For example
vfwfrxfs2#
@pureliumy actually the problem persists when select is used with remote + filter option - the options are not populated unless users clicks the select element.
What is the best way to display the default value for object if options array is empty?
ttvkxqim3#
This problem still persists in version 2.15.9, only if the remote property is enabled.
I handle it this way, but as now I have to handle remote search, it stopped working: