Item.vue
667 Bytes
<script>
export default {
name: 'MenuItem',
functional: true,
props: {
icon: {
type: String,
default: ''
},
title: {
type: String,
default: ''
}
},
render(h, context) {
// render函数的作用是将虚拟dom渲染成真实dom
// render函数的第二个参数是一个对象,里面包含了所有的props,作用是为了避免在render函数中使用this
const { icon, title } = context.props
const vnodes = []
if (icon) {
vnodes.push(<svg-icon icon-class={icon}/>)
}
if (title) {
vnodes.push(<span slot='title'>{(title)}</span>)
}
return vnodes
}
}
</script>