element-UI 的 el-select 組件里,當 v-model 綁定為對象類型,並對其設定默認值
<el-select v-model="form.InWindowPositionType"> <el-option v-for="item in positionList" :value="item.value" :key="item.value" :label='item.label'></el-option> </el-select>
在 data 中設 form.InWindowPositionType 與 列表的 value 相等 ,則認為對 selected 設置了默認值,但是選擇器里的顯示結果為 value 值,而非 label ,
{ value: 1, label: 'java' },
{ value: 2, label: 'node' },
{ value: 3, label: 'python' },
問題在於數據類型,form.InWindowPositionType 的值為 String ,而 列表的 value 為 Number,並不全等,導致無法找到對應的項 。。。所以需要對數據類型進行轉換
