The default value of the Select drop-down box in Element Ui fails to be initialized.

Requirement: When the page loads, while initializing the options, give the Select a default selection value.

<el-select v-model="Id" cleatable placeholder="请选择">
    <!-- Id 是需要默认的值  postionArr是从后端获取的可选列表-->
   <el-potion v-for="(item,index) in potionArr" :key="item.id" :label="item.name" :value="item.id">
</el-select>

Error condition: Not bound to the corresponding option

The passed value is assigned to the drop-down box, but it is displayed directly in the content, so the specific option should be selected.

Problem analysis: The passed default value does not match the value in el-potion, and Select cannot select correctly.

1. Your option value does not exist in the potion of Select. You can output your optional list on the console to check whether it contains data. If your default value does not exist in the optional list, you can filter the optional list when you get the default value. If there is no matching object, you can add it manually.

2. Check whether the type of the value you pass in is consistent with the type of value in the potion. Inconsistent types will also cause Select to fail to select correctly. It is necessary to unify the types of the two values.

According to the above two situations, the default selection failure of Select can basically be solved.

Guess you like

Origin blog.csdn.net/youyudehan/article/details/132858166