el-select get label value

For novices, it is enough to obtain the value in el-select daily, but there are always some special business scenarios that need to obtain the label. Tried a lot of silly ways

1. It will make the returned data into a map data, and directly mapList[id] to obtain the currently selected label. Although it is feasible, it is not recommended;

2. The second method is to set the value of value in the value of el-select to id+','+label, so that the value is the combination of the target value and the label. It feels safer than the above, but there is one more step in the result processing It is not easy to operate and decompose the results;

3. In the end, you still have to use ref, just add ref='selectLable' in el-select, and directly use this.$refs.selectLable.selected.label when getting the value. This step is usually performed in the last step. Don't get it from the onchange event, you get the last label, which is not satisfactory.

Note: If the multi-select multiple attribute is selected in el-select, then the value of this.$refs.selectLable.selected.label cannot be obtained, because the result at this time is an array, we have to traverse it

this.$refs.selectLable.selected.map(v=>v.label) can get the value of the label array in this way.
-----------------------------------
©Copyright belongs to the author: Original works from 51CTO blogger nation1, Please contact the author to obtain reprint authorization, otherwise legal responsibility will be pursued
vue- element el-select obtains label
Reprinted at: https://blog.51cto.com/u_11451782/3662591

 

Guess you like

Origin blog.csdn.net/ysfengshu/article/details/130225376