admin管理员组文章数量:1328953
I've been trying to create a simple skeleton loader in Vuetify that is shown while the document's resources (like images) are being loaded and then hidden (replaced with a <v-card>
) when everything is fully loaded.
Currently, I have this <v-skeleton-loader>
:
<v-skeleton-loader v-if="loading == true" :loading="loading" transition="fade-transition" type="card">
</v-skeleton-loader>
My v-card
element uses v-show
like this:
<v-card max-width="344" v-show="loaded">
For reactive properties, I have:
data: () => ({
loading: true,
loaded: false
})
I am trying to update the values of those properties using the updated
lifecycle hook of Vue.js:
updated: function() {
if (document.readyState == 'plete') {
this.loading = false;
this.loaded = true;
}
}
Currently, Vue Devtools tells me that the properties are not being updated with their new values, defined in the updated
hook. How can I change that so the values are properly updated when the readyState
of the DOM has changed to plete
?
I've been trying to create a simple skeleton loader in Vuetify that is shown while the document's resources (like images) are being loaded and then hidden (replaced with a <v-card>
) when everything is fully loaded.
Currently, I have this <v-skeleton-loader>
:
<v-skeleton-loader v-if="loading == true" :loading="loading" transition="fade-transition" type="card">
</v-skeleton-loader>
My v-card
element uses v-show
like this:
<v-card max-width="344" v-show="loaded">
For reactive properties, I have:
data: () => ({
loading: true,
loaded: false
})
I am trying to update the values of those properties using the updated
lifecycle hook of Vue.js:
updated: function() {
if (document.readyState == 'plete') {
this.loading = false;
this.loaded = true;
}
}
Currently, Vue Devtools tells me that the properties are not being updated with their new values, defined in the updated
hook. How can I change that so the values are properly updated when the readyState
of the DOM has changed to plete
?
3 Answers
Reset to default 5updated
hook is called only when a ponent is updated. Vue lifecycle isn't tied to DOM events. If there were no updates after page load, updated
won't be triggered.
This can be done with regular DOM event listener:
created() {
const readyHandler = () => {
if (document.readyState == 'plete') {
this.loading = false;
this.loaded = true;
document.removeEventListener('readystatechange', readyHandler);
}
};
document.addEventListener('readystatechange', readyHandler);
readyHandler(); // in case the ponent has been instantiated lately after loading
}
You must observe document.readyState:
mounted: function() {
var that = this;
if (document.readyState === 'plete')
this.$set(that, 'loaded', true);
else
document.addEventListener('readystatechange', function() {
if (document.readyState === 'plete')
that.$set(that, 'loaded', true);
})
}
<v-card class="card" v-if="loaded">
<h2>xxxx</h2>
</v-card>
<v-sheet class="pa-3" v-else>
<v-skeleton-loader
class="mx-auto"
type="card"
></v-skeleton-loader>
</v-sheet>
本文标签: javascriptVuetify Hide a skeleton loader after a element loadsStack Overflow
版权声明:本文标题:javascript - Vuetify: Hide a skeleton loader after a element loads - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742225510a2436239.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论