Item.vue 1.01 KB
<script>
export default {
  name: 'MenuItem',
  functional: true,
  props: {
    icon: {
      type: String,
      default: ''
    },
    errorUrl: {
      type: String,
      default: 'http://img1.xcarimg.com/exp/2872/2875/2937/20101220130509576539.jpg'
    },
    title: {
      type: String,
      default: ''
    }
  },
  render(h, context) {
    const { icon, title,errorUrl } = context.props
    const vnodes = []

    if (icon) {
      //console.log(icon,'item in icon 这里进行判断处理是相对 还是 绝对地址')
      var rxp = /^[a-zA-z]+:\/\/[^\s]*$/;
      if(rxp.test(icon)){
        vnodes.push(<img class='jpgClass' src={icon} />)
      }else{
        vnodes.push(<svg-icon icon-class={icon}/>)
      }
    }

    if (title) {
      vnodes.push(<span slot='title'>{(title)}</span>)
    }
    return vnodes
  }
}
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
// .el-submenu__title i {
//   color: #fff;
// }
  .jpgClass{
    width: 14px;
    height: 14px;
    margin-right: 16px;
  }
</style>