<template>
<div id="app">
<my-render level="1">this is a book</my-render>
</div>
</template>
<script>
import Vue from 'vue'
Vue.component('my-render', {
render: function (createElement) {
return createElement(
'h' + this.level, // 标签名称
this.$slots.default // 子节点数组
)
},
props: {
level: {
type: Number,
required: true
}
}
})
export default {
data() {
return {
}
},
components: {
},
created: function(){
},
watch:{
},
mounted(){
},
methods: {
},
computed: {
}
}
</script>
<style >
</style>
Vue官方文档(41):在组件中直接使用渲染函数render
最新推荐文章于 2024-11-01 14:22:21 发布