原来代码
<script>
export default {
name: 'Item',
functional: true,
props: {
icon: {
type: String,
default: ''
},
title: {
type: String,
default: ''
}
},
render(h, context) {
const { icon, title } = context.props
const vnodes = []
if (icon) {
vnodes.push(<svg-icon icon-class={icon}/>)
}
if (title) {
vnodes.push(<span slot='title'class='system-menu-title'>{(title)}</span>)
}
return vnodes
}
}
</script>
改进之后
const { icon, title } = context.props
const vnodes = []
if (icon) {
const elHtml = createElement('svg-icon',{
attrs: {
'icon-class': icon
}
})
vnodes.push(elHtml)
}
if (title) {
const elHtml = createElement('span',{
attrs: {
slot: title,
}
},title)
vnodes.push(elHtml)
}
return vnodes
网友评论