You might not know the v-cloak
directive as it happens to be somewhere in the docs where you probably don’t pay attention to it. Until that day where you have a use case.
HTML rendering phases
What can be annoying with Vue.js is that the HTML elements are present in your page before Vue.js reads and compiles it.
Note : I am referring to simple use cases where you render components in an existing app, not SPA setups.
id="app">
Hello {{ name }}
new Vue({
el: '#app',
data () {
return {
name: 'Simon'
}
}
})
In this example, for a brief moment, the whole content of the It’s only after Vue.js core and the content of the This “brief moment” still gives users a poor experience, and its duration depends on the user’s bandwidth. During this time, they can see the mustache expression Note : In Chrome’s developer tools, you can simulate a slow bandwidth in the “Network” tab (look for “throttling” options). Quoting the docs : This directive will remain on the element until the associated Vue instance finishes compilation. Meaning that we can add some CSS to hide it before the component is compiled. Refresh and see the magic of Vue.js operating once again. No more excuse for this flashing HTML mess on the startup of your apps. At the beginning of this post I said that I was not referring to single-page apps. That’s not 100% true. When an SPA starts up, there is some HTML that is sent to the user. It is the content of tag are loaded that it will be processed and compiled using the data provided.
Hello {{ name }}
. Needless to say there is probably more templating in your app than in this simple example.The
v-cloak
directive
How about single-page apps ?
index.html
. It probably doesn’t contain anything but the v-cloak
to prevent the browser from rendering its content.
Links
v-cloak
directive
Latest posts