<template>
    <!-- vue2 同名的独立 attribute 始终覆盖 v-bind="object"，无视声明的顺序 -->
    <el-select
        v-bind="$attrs"
        filterable
        clearable
        default-first-option
        value-key="code"
        v-on="$listeners"
        @change="handleChange"
    >
        <el-option
            v-for="(item,index) in options"
            :key="index"
            :label="item[labelKey]"
            :value="item[valueKey]"
        >
        </el-option>
    </el-select>
</template>

<script>
export default {
    props: {
        //* options 成员格式为{label:'xxx',value:'xxx'},label和value由labelKey和valueKey定义
        options: {
            type: Array,
            default(){
                return []
            },
        },
        labelKey: {
            type: String,
            default: 'label',
        },
        valueKey: {
            type: String,
            default: 'value',
        },
    },
    methods:{
        handleChange(){
            // console.log(arguments)
        }
    }
}
</script>
