DictSelectTag.vue 1.1 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
<template>
  <a-select :placeholder="placeholder" :value="value" @change="handleInput">
    <a-select-option value="">请选择</a-select-option>
    <a-select-option v-for="(item, key) in dictOptions" :key="key" :value="item.value">{{ item.text }}</a-select-option>
  </a-select>
</template>

<script>
  import {ajaxGetDictItems} from '@/api/api'

  export default {
    name: "DictSelectTag",
    props: {
      dictCode: String,
      placeholder: String,
      value: String,// 1.接收一个 value prop
    },
    data() {
      return {
        dictOptions: [],
      }
    },
    created() {
      console.log(this.dictCode);
      //获取字典数据
      this.initDictData();
    },
    methods: {
      initDictData() {
        //根据字典Code, 初始化字典数组
        ajaxGetDictItems(this.dictCode, null).then((res) => {
          if (res.success) {
//                console.log(res.result);
            this.dictOptions = res.result;
          }
        })
      },
      handleInput(val) {
        console.log(val);
        this.$emit('input', val); // 2.触发 input 事件,并传入新值
      }
    }
  }
</script>

<style scoped>
</style>