VueJS Render VNode


Given a VueJS VNode object, how do I get the HTML element that would be generated if it were rendered?


> temp1
VNode {tag: "h1", data: undefined, children: Array(1), text: undefined, elm: undefined, …}
> temp1.children[0]
VNode {tag: undefined, data: undefined, children: undefined, text: "Test", elm: undefined, …}
> doSomething(temp1)


I'm attempting to build a small VueJS wrapper around the library.

To mimic the behavior of HTML tables in my markup, I want something like the following:

        <datatable-row v-for="person in people">
            <td>{{ }}</td>
            <td>{{ person.age }}</td>
            <td>{{ person.salary }}</td>

What I've done so far

I've started to implement this as follows:


    <table ref="table" class="display table table-striped" cellspacing="0" width="100%">

/* global $ */
export default {
    data: () => ({
        instance: null
    mounted() {
        this.instance = $(this.$refs.table).dataTable();
        this.$el.addEventListener("dt.row_added", function(e) {
    methods: {
        addRow(row) {
            // TODO <-----


/* global CustomEvent */
export default {
    mounted() {
        this.$nextTick(() => {
            this.$el.dispatchEvent(new CustomEvent("dt.row_added", {
                bubbles: true,
                detail: this.$slots.default.filter(col => col.tag === "td")
    render() { return ""; }

What this currently does:

  • When the page loads, the DataTable is initialized. So the column headers are properly formatted and I see "Showing 0 to 0 of 0 entries" in the bottom left
  • The CustomEvent is able to bubble up past the <tbody> and be caught by the DataTable element successfully (circumventing the limitation in VueJS that you can't listen to events on slots)

What this does not do:

  • Actually add the row

My event is giving me an array of VNode objects. There's one VNode per column in my row. The DataTables API has an addRow function which can be called like so:

this.instance.row.add(["col1", "col2", "col3"]);

In my case, I want the resultant element from the rendering of the VNode to be the elements in this array.

var elems = [];
for (var i = 0; i < row.length; i++)
    elems[i] = compile(row[i]);

Unfortunately this compile method eludes me. I tried skimming the VueJS documentation and I tried Googling it, but no dice. I tried manually passing the createElement function (the parameter passed to the render method) but this threw an error. How can I ask VueJS to render a VNode without injecting the result into the DOM?



I ran into the same issue wanting to do basically the same thing with a row details template for

One solution could be to create a generic component that renders out a VNode and instantiate that programmatically. Here is how my setup for a dynamic detail row that I insert using datatable's row.child() API.


export default {
    props: ['node'],
    render(h, context) {
        return this.node ? this.node : ''


Include the renderer component from above

import Vue from 'vue'
import nodeRenderer from './RenderNode'

Instantiate and mount the renderer to get the compiled HTML

// Assume we have `myVNode` and want its compiled HTML

const DetailConstructor = Vue.extend(nodeRenderer)

const detailRenderer = new DetailConstructor({
    propsData: {
        node: myVNode

// detailRenderer.$el is now a compiled DOM element 


Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us Javascript

©2020 All rights reserved.