DataSelect.vue 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <template>
  2. <el-select v-model="newValue" placeholder="请选择">
  3. <el-option
  4. v-for="item in options"
  5. :key="item[valueKay]"
  6. :label="item.label"
  7. :value="item[valueKay]"
  8. >
  9. </el-option>
  10. </el-select>
  11. </template>
  12. <script>
  13. import { getList } from '@/api/dict';
  14. export default {
  15. name: 'DataSelect',
  16. props: {
  17. value: {
  18. type: String,
  19. default: ''
  20. },
  21. params: {
  22. type: String,
  23. default: ''
  24. },
  25. valueKay: {
  26. type: String,
  27. default: 'value'
  28. }
  29. },
  30. data() {
  31. return {
  32. newValue: this.value,
  33. options: []
  34. };
  35. },
  36. watch: {
  37. value: {
  38. handler(val) {
  39. this.newValue = val;
  40. },
  41. immediate: true
  42. },
  43. newValue: {
  44. handler(val) {
  45. this.$emit('input', val);
  46. },
  47. immediate: true
  48. }
  49. },
  50. created() {
  51. this.loadData();
  52. },
  53. methods: {
  54. async loadData() {
  55. const { data } = await getList({
  56. dictCode: this.params
  57. });
  58. this.options = data.map(x => ({
  59. value: x.value,
  60. label: x.name
  61. }));
  62. }
  63. }
  64. };
  65. </script>
  66. <style lang="scss" scoped></style>