TIL Vue's Render Function
POSTED ON:
In Vue, you can render HTML content in the <template>
section.
But say you need to dynamically render HTML.
A good example is that you want to generate a lot of list items, and writing them in the <template>
section makes it look like spaghetti.
export default {
render (h) {
return h('div', {}, [...]);
}
}
Dynamic rendering of a component
h
stands for hypertext (As in HTML)
Vue.component('example', {
props; ['ok'],
render(h) {
return this.ok ? h(Foo) : h(Bar)
}
})
For the react version:
const App = () => {
return React.createElement(
"div",
{},
React.createElement("h1", {}, "Adopt Me!")
);
};
A better example is located in the Vue Docs, about switching between various header tags.
Related TILs
Tagged: vue