Item.vue 729 Bytes
<script>
export default {
  name: 'MenuItem',
  functional: true,
  props: {
    icon: {
      type: String,
      default: ''
    },
    title: {
      type: String,
      default: ''
    }
  },
  render(h, context) {
    const { icon, title } = context.props
    const vnodes = []

    if (icon) {
      /** 图标分为svg和element自带的两种,主要通过classname区分,带el-的为自带的图标,所以后期如果需要添加svg图标,注意名字不要带el- */
      icon.includes('el-')
        ? vnodes.push(<i class={icon}></i>)
        : vnodes.push(<svg-icon icon-class={icon} />)
    }

    if (title) {
      vnodes.push(<span slot='title'>{title}</span>)
    }
    return vnodes
  }
}
</script>