<template>
    <svg :class="svgClass" aria-hidden="true" v-on="$listeners">
        <use :xlink:href="iconName"/>
    </svg>

    <!-- 在组建中直接使用，示例  icon-class值为svg的文件名-->
    <!-- <svg-icon icon-class="user"></svg-icon> -->
</template>

<script>
    export default {
        name: 'SvgIcon',
        props: {
            iconClass: {
                type: String,
                required: true
            },
            className: {
                type: String,
                default: ''
            }
        },
        computed: {
            iconName() {
                return `#icon-${this.iconClass}`
            },
            svgClass() {
                if (this.className) {
                    return 'svg-icon ' + this.className
                } else {
                    return 'svg-icon'
                }
            }
        }
    }
</script>

<style scoped>
    .svg-icon {
        width: 1.3em;
        height: 1.3em;
        fill: currentColor;
        overflow: hidden;
        vertical-align: middle;
    }
</style>