By the docs I do not fully understand when I should use render: h => h(App)
function.
For example I have very simple Vue app:
import Vue from 'vue'
import App from './App.vue'
new Vue({
el: '#app',
components: { App }
})
What is the case when I need add to code: render: h => h(App)
?
Vue provides an h() function for creating vnodes: js import { h } from 'vue' const vnode = h( 'div', // type { id: 'foo', class: 'bar' }, // props [ /* children */ ] ) h() is short for hyperscript - which means "JavaScript that produces HTML (hypertext markup language)".
Love it or hate it, JSX is a popular extension to JavaScript that allows XML tokens in your scripts. If you want to create templates in your script files and you find Vue's render() function to be difficult to work with, JSX may be just what you need.
A VNode is an "element" in Vue's Virtual DOM, which is what Vue uses to create the real HTML DOM that's rendered on the page.
Functional components defined as a Single-File Component in a *. vue file also receives proper template compilation, Scoped CSS and hot-reloading support. To denote a template that should be compiled as a functional component, add the functional attribute to the template block.
In the example you posted, App.vue
represents the main app wrapper - all related .vue
component files would be imported there.
So in your Vue
instance you defined the components object, and added the App component, but how would you exactly mount that component to the instance and display it?
A couple of things to keep in mind:
.vue
file, so you don't have a template tag option. This is a pure .js
file<App></App>
into the template
property because you are using runtime only build so the template option is not availableOne option is using render functions. It's what Vue.js
does under the hood. It takes your template and then template compiler converts it to render functions.
Alternatively, instead of a render function, you can the use spread operator:
import Vue from 'vue'
import App from './App.vue'
new Vue({
el: '#app',
...App
})
From the docs:
Vue recommends using templates to build your HTML in the vast majority of cases. There are situations however, where you really need the full programmatic power of JavaScript. That’s where you can use the render function
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With