
vue2如何在template中渲染通过h函数生成的dom
作者: boyyang
分类: 前端开发
发布: 2024-09-13 04:51:06
更新: 2025-03-23 12:34:59
浏览: 218
在react中使用的是jsx,使用起来非常方便。在对table的column进行配置的时候,如果需要对某一单元格进行特殊处理,如渲染一个按钮,或者其它自定义dom结构,便会有一些问题。
所以为了实现该功能,网上找了一圈终于找到了解决方案,通过该方案便能处理一些特殊情况下需要传递一些dom结构。
<script>
import { h } from "vue";
export default {
name: "VNodeTest",
components: {
Vnodes: {
functional: true,
render: (h, ctx) => ctx.props.vnodes
}
},
methods: {
render(){
return h('div', {}, 'xxx')
}
}
};
</script>
<template>
<div class="wrapper">
<Vnodes :vnodes="render()"></Vnodes>
</div>
</template>