VabDictSelect.vue 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <template>
  2. <el-select
  3. :value="value"
  4. @input="$emit('input', $event)"
  5. v-bind="$attrs"
  6. @change="changeData"
  7. >
  8. <el-option
  9. v-for="item in dict"
  10. :key="item.id || item.dictValue"
  11. :label="item.dictName"
  12. :value="item.dictValue"
  13. />
  14. </el-select>
  15. </template>
  16. <script>
  17. export default {
  18. name: 'VabDictSelect',
  19. props: {
  20. dictCode:{
  21. required:true,
  22. type:String
  23. },
  24. value:[String,Number],
  25. },
  26. emits: ['change', 'update:value'],
  27. watch:{
  28. value(newVal){
  29. if(typeof newVal == 'number'){
  30. // eslint-disable-next-line vue/no-mutating-props
  31. this.value = newVal+'';
  32. this.$forceUpdate();
  33. }
  34. console.log(this.dict[0].dictValue ,this.value)
  35. }
  36. },
  37. data(){
  38. return {
  39. dict:[],
  40. }
  41. },
  42. computed: {
  43. localModelValue: {
  44. get() {
  45. return this.modelValue;
  46. },
  47. set(newValue) {
  48. this.$emit('update:value', newValue);
  49. }
  50. }
  51. },
  52. methods:{
  53. changeData(){
  54. this.$emit('change',this.value)
  55. }
  56. },
  57. created() {
  58. this.dict = this.$getDictList(this.dictCode);
  59. }
  60. }
  61. </script>