How to render $createElement in nuxt?

Viewed 65

I didn't find any documentation on $createElement in nuxt.

I tried using the following code to create an HTML Element:

const elem = this.$createElement('h' + this.hlevel)
elem.text = this.myTitle
console.log('My Element:', elem)

Result is an object but I do not know how to render it.

Is it really to create an HTML Element or should this be used for a different use case?

2 Answers

Simply use

render() {
  return this.$createElement('h' + this.hlevel, this.myTitle)
},

Also make sure you don't have

<template></template>

as this will overwrite render().

Note: as kissu commented, the use of h() or $createElement() is probably overkill :)

Related