解决初始化下拉选项的问题

This commit is contained in:
aixianling
2024-10-23 10:53:15 +08:00
parent 398b3e799c
commit af296ebf51
2 changed files with 18 additions and 18 deletions

View File

@@ -63,23 +63,25 @@ export default {
this.tableData = res.data?.page?.records || [] this.tableData = res.data?.page?.records || []
} }
}) })
},
getOptions() {
const ops = {}
this.tableData.forEach(e => {
ops[e.groupCode] = e.groupName
})
return Object.entries(ops).map(([key, value]) => ({label: value, value: key}))
} }
}, },
watch: { watch: {
search: { search: {
deep: true, handler() { immediate: true, deep: true, handler() {
this.getTableData()
}
}
},
created() {
this.getTableData().then(() => { this.getTableData().then(() => {
this.options = this.tableData.map(e => ({ if (this.options.length == 0) this.options = this.getOptions()
label: e.groupName, value: e.groupCode
}))
}) })
} }
} }
}
}
</script> </script>
<template> <template>
@@ -108,6 +110,7 @@ export default {
.AppGroupMonitorTable .dv-scroll-board, .AppGroupMonitorTable .scrollTable { .AppGroupMonitorTable .dv-scroll-board, .AppGroupMonitorTable .scrollTable {
height: calc(100% - 80px) !important; height: calc(100% - 80px) !important;
} }
.AppGroupMonitorTable .el-select { .AppGroupMonitorTable .el-select {
width: 140px !important; width: 140px !important;
} }

View File

@@ -71,17 +71,14 @@ export default {
}, },
watch: { watch: {
search: { search: {
deep: true, handler() { immediate: true, deep: true, handler() {
this.getTableData()
}
}
},
created() {
this.getTableData().then(() => { this.getTableData().then(() => {
this.options = this.getOptions() if (this.options.length == 0) this.options = this.getOptions()
}) })
} }
} }
}
}
</script> </script>
<template> <template>