Skip to content

Instantly share code, notes, and snippets.

@adamwathan
Last active February 26, 2023 14:26
Show Gist options
  • Save adamwathan/3584d1904e4f4c36096f to your computer and use it in GitHub Desktop.
Save adamwathan/3584d1904e4f4c36096f to your computer and use it in GitHub Desktop.
Useful CSS utilities for Vue.js cloaking

Handy helpers for controlling visibility of elements until Vue has compiled.

Use like:

<div v-cloak>
  <h1>
    <span class="v-cloak--inline">Loading...</span> <!-- Only displayed before compiling -->
    <span class="v-cloak--hidden">{{ post.title }}</span> <!-- Hidden until compiling is finished -->
  </h1>
</div>

Includes variations for block, inline, and inline-block display attributes.

[v-cloak] .v-cloak--block {
  display: block;
}
[v-cloak] .v-cloak--inline {
  display: inline;
}
[v-cloak] .v-cloak--inlineBlock {
  display: inline-block;
}
[v-cloak] .v-cloak--hidden {
  display: none;
}
[v-cloak] .v-cloak--invisible {
  visibility: hidden;
}
.v-cloak--block,
.v-cloak--inline,
.v-cloak--inlineBlock {
  display: none;
}
@sergeifilippov
Copy link

Typo, in dispay ;)

@blomdahldaniel
Copy link

The typo is on the line between the gods blocks "dispay attributes".
Great stuff you have shared, so simple but yet powerfull! 😄 thanks!

@xtrasmal
Copy link

xtrasmal commented Dec 5, 2015

Thanks Adam! Just what I needed.

@valmayaki
Copy link

Thanks Adam! An info I skipped from reading the docs, it was very useful to me.

@johnRivs
Copy link

God bless.

@ManiruzzamanAkash
Copy link

Simple, But very useful. Thanks Adam..

@marufmax
Copy link

Useful. Thanks

@annymosse
Copy link

thanks too much

@terryupton
Copy link

This is super useful thanks @adamwathan

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment