index.vue 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <template>
  2. <el-select v-model="valueTurn" :multiple="multiple" :placeholder="placeholder">
  3. <el-option
  4. v-for="item in options"
  5. :key="item.value"
  6. :label="item.text"
  7. :value="item.value"
  8. />
  9. </el-select>
  10. </template>
  11. <script>
  12. export default {
  13. name: 'OptionSet',
  14. props: {
  15. placeholder: {
  16. type: String,
  17. default: ''
  18. },
  19. code: {
  20. type: String,
  21. default: ''
  22. },
  23. value: {
  24. type: [String, Number, Array],
  25. default: () => ['', 0, []]
  26. },
  27. multiple: {
  28. type: Boolean,
  29. default: () => false
  30. }
  31. },
  32. data: function() {
  33. return {
  34. selectValue: '',
  35. options: []
  36. }
  37. },
  38. computed: {
  39. // valueTurn() {
  40. // get: () => {
  41. // typeof this.value === 'string' ? return this.value : return this.value.toString()
  42. // if (typeof this.value === 'string') {
  43. // return this.value
  44. // } else {
  45. // return this.value.toString()
  46. // }
  47. // }
  48. // }
  49. valueTurn: {
  50. get: function() {
  51. if (typeof this.value === 'string') {
  52. return this.value
  53. } else if (typeof this.value === 'number') {
  54. return this.value.toString()
  55. } else if (typeof this.value === 'object') {
  56. return this.value
  57. }
  58. return this.value
  59. },
  60. set: function(newValue) {
  61. if (typeof this.value === 'string') {
  62. // this.value = newValue
  63. this.$emit('update:value', newValue)
  64. } else if (typeof this.value === 'number') {
  65. // this.value = parseInt(newValue)
  66. this.$emit('update:value', parseInt(newValue))
  67. } else if (typeof this.value === 'object') {
  68. this.$emit('update:value', newValue)
  69. }
  70. }
  71. }
  72. },
  73. watch: {
  74. // 'value': function(newVal, oldVal) {
  75. // debugger
  76. // typeof newVal === 'string' ? this.selectValue = newVal : this.selectValue = newVal.toString()
  77. // },
  78. // 'selectValue': function(newVal, oldVal) {
  79. // debugger
  80. // typeof this.value === 'string' ? this.$emit('update:value', newVal) : this.$emit('update:value', parseInt(newVal))
  81. // }
  82. },
  83. created() {
  84. this.multiple
  85. this.getOptions()
  86. },
  87. methods: {
  88. async getOptions() {
  89. this.options = await this.$store.dispatch('optionset/formatterData', this.code)
  90. }
  91. }
  92. }
  93. </script>
  94. <style>
  95. </style>