Commit c098c3ab by 李伟康

fix(SelectComponent): 修复选择组件在索引为-1时的默认值处理

当 selectIndex 为 -1 时,将其重置为 0 以避免访问无效数组元素。
同时优化了监听器中的索引查找逻辑,确保在找不到匹配项时也设置默认值。
1 parent ea702a3a
......@@ -49,6 +49,7 @@ export default {
computed: {
selectValue () {
let { selectList, selectIndex, labelKey } = this
if (selectIndex == -1) selectIndex = 0
return selectList[selectIndex][labelKey]
}
},
......@@ -57,8 +58,10 @@ export default {
immediate: true,
deep: true,
handler (n) {
let { selectList , valueKey} = this
this.selectIndex = selectList.findIndex(e => e[valueKey] == n)
let { selectList, valueKey } = this,
selectIndex = selectList.findIndex(e => e[valueKey] == n)
if (selectIndex == -1) selectIndex = 0
this.selectIndex = selectIndex
}
}
},
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!