Home > Back-end >  How to render $createElement in nuxt?
How to render $createElement in nuxt?

Time:08-15

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?

CodePudding user response:

createElement is basically an alias to h, you can read more about it here: https://vuejs.org/guide/extras/render-function.html#render-functions-jsx.

Those are aimed towards highly customizable dynamic markup generation. If you don't need that (or you issue could be solved with a dynamic component for example), it may probably be overkill.

CodePudding user response:

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