Vue element-ui select component, cannot change the label value after initializing the assignment?

<el-select v-model="postForm.roleId" placeholder="" @change="selectBD">
   <el-option 
     v-for="item in roleList" 
     :key="item.id" 
     :value="item.id" 
     :label="item.name" />
</el-select>

roleList and postFrom.roleId are both obtained through the API and can be assigned correctly, but when you select the switch later, the postForm.roleId will change correctly, but the ui will not be updated, as shown in the figure. No matter how to switch, the postFrom.roleId is correct, but the ui remains the same.

clipboard.png

Aug.10,2021

Why don't you try putting roleId outside and passing it to select?

<el-select v-model="roleId" placeholder="" @change="selectBD">

finally knows the reason. The data object I got has the attribute of a vue.$set bforce c, but I use the locally defined d attribute, and then assign the value of c to d, which is no problem. However, due to the responsive update mechanism of vue, it is impossible to monitor the new attributes of the object, so we must use the vue.$set () method to add new attributes to achieve responsive updates.


paste the data and code


probably because the format or value of postForm.roleId in data does not correspond to that in roleList. Check it.


learn about this attribute in el-select in element value-key= "id" . The value you bind needs to be consistent with the value rendered. If this happens, you should bind an object to select, not a single value!

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b36afd-41074.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b36afd-41074.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?