スケルトン
<b-skeleton>
は、データのフェッチまたは計算中に、いくつかのコンポーネントタイプに対してローディング状態を表示できるBootstrapVueのカスタムコンポーネントです。
BootstrapVue v2.17.0
以降で使用できます。
例:基本的な使用方法
<template>
<div>
<div class="d-flex align-items-center mb-3">
<b-progress class="w-100" :max="maxLoadingTime" height="1.5rem">
<b-progress-bar :value="loadingTime" :label="`${((loadingTime / maxLoadingTime) * 100).toFixed(2)}%`"></b-progress-bar>
</b-progress>
<b-button class="ml-3" @click="startLoading()">Reload</b-button>
</div>
<b-skeleton-wrapper :loading="loading">
<template #loading>
<b-card>
<b-skeleton width="85%"></b-skeleton>
<b-skeleton width="55%"></b-skeleton>
<b-skeleton width="70%"></b-skeleton>
</b-card>
</template>
<b-card>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas viverra nunc sapien,
non rhoncus elit tincidunt vitae. Vestibulum maximus, ligula eu feugiat molestie,
massa diam imperdiet odio, vitae viverra ligula est id nisi. Aliquam ut molestie est.
Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac
turpis egestas. Phasellus at consequat dui. Aenean tristique sagittis quam,
sit amet sollicitudin neque sodales in.
</b-card>
</b-skeleton-wrapper>
</div>
</template>
<script>
export default {
data() {
return {
loading: false,
loadingTime: 0,
maxLoadingTime: 3
}
},
watch: {
loading(newValue, oldValue) {
if (newValue !== oldValue) {
this.clearLoadingTimeInterval()
if (newValue) {
this.$_loadingTimeInterval = setInterval(() => {
this.loadingTime++
}, 1000)
}
}
},
loadingTime(newValue, oldValue) {
if (newValue !== oldValue) {
if (newValue === this.maxLoadingTime) {
this.loading = false
}
}
}
},
created() {
this.$_loadingTimeInterval = null
},
mounted() {
this.startLoading()
},
methods: {
clearLoadingTimeInterval() {
clearInterval(this.$_loadingTimeInterval)
this.$_loadingTimeInterval = null
},
startLoading() {
this.loading = true
this.loadingTime = 0
}
}
}
</script>
タイプ
<b-skeleton>
は、プロジェクト内の様々なコンポーネントを表すために、様々な基本タイプをサポートしています。
<h5>Text (default)</h5>
<b-skeleton></b-skeleton>
<h5 class="mt-3">Avatar</h5>
<b-skeleton type="avatar"></b-skeleton>
<h5 class="mt-3">Input</h5>
<b-skeleton type="input"></b-skeleton>
<h5 class="mt-3">Button</h5>
<b-skeleton type="button"></b-skeleton>
スケルトンアニメーション
<b-skeleton>
は、さまざまなアニメーションをサポートしています。コンポーネントごとに設定するか、設定でグローバルに変更できます。
<h5>Wave (default)</h5>
<b-card>
<b-skeleton animation="wave" width="85%"></b-skeleton>
<b-skeleton animation="wave" width="55%"></b-skeleton>
<b-skeleton animation="wave" width="70%"></b-skeleton>
</b-card>
<h5 class="mt-3">Fade</h5>
<b-card>
<b-skeleton animation="fade" width="85%"></b-skeleton>
<b-skeleton animation="fade" width="55%"></b-skeleton>
<b-skeleton animation="fade" width="70%"></b-skeleton>
</b-card>
<h5 class="mt-3">Throb</h5>
<b-card>
<b-skeleton animation="throb" width="85%"></b-skeleton>
<b-skeleton animation="throb" width="55%"></b-skeleton>
<b-skeleton animation="throb" width="70%"></b-skeleton>
</b-card>
<h5 class="mt-3">None</h5>
<b-card>
<b-skeleton animation width="85%"></b-skeleton>
<b-skeleton animation width="55%"></b-skeleton>
<b-skeleton animation width="70%"></b-skeleton>
</b-card>
ヘルパーコンポーネント
<b-skeleton>
ヘルパーコンポーネントを使用して、既存のコンポーネントをすばやくスキャフォールディングします。
テーブル
<b-skeleton-table>
を使用すると、rows
および columns
プロップを使用してテーブルのサイズを定義することにより、基本的なテーブル構造をスキャフォールディングできます。table-props
プロパティを介してプロップをテーブルに直接渡すことができます。これは<b-table-simple>
と同じプロップをサポートしています。<b-table-simple>
の完全なリストについては、ドキュメントを参照してください。
<b-skeleton-table
:rows="5"
:columns="4"
:table-props="{ bordered: true, striped: true }"
></b-skeleton-table>
画像
<b-skeleton-img>
を使用して画像を表します。デフォルトでは16:9のアスペクト比を使用し、レスポンシブなサイズ調整を行います。no-aspect
を適用してこれを上書きし、height
および width
プロップを使用して独自のサイズを設定できます。
<b-row>
<b-col>
<b-skeleton-img></b-skeleton-img>
</b-col>
<b-col>
<b-skeleton-img></b-skeleton-img>
</b-col>
<b-col cols="12" class="mt-3">
<b-skeleton-img no-aspect height="150px"></b-skeleton-img>
</b-col>
</b-row>
カード画像
<b-skeleton-img>
を使用して <b-card>
内の画像を表します。card-img
プロップを画像の位置に設定することを忘れないでください。これにより、適切なボーダー半径が適用されます。
<b-row>
<b-col cols="12" md="6">
<h5>Image top</h5>
<b-card no-body img-top>
<b-skeleton-img card-img="top" aspect="3:1"></b-skeleton-img>
<b-card-body>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas viverra nunc sapien,
non rhoncus elit tincidunt vitae.
</b-card-body>
</b-card>
</b-col>
<b-col cols="12" md="6">
<h5>Image bottom</h5>
<b-card no-body img-bottom>
<b-card-body>
Vestibulum maximus, ligula eu feugiat molestie, massa diam imperdiet odio, vitae viverra
ligula est id nisi. Aliquam ut molestie est.
</b-card-body>
<b-skeleton-img card-img="bottom" aspect="3:1"></b-skeleton-img>
</b-card>
</b-col>
</b-row>
<b-row class="mt-md-3">
<b-col cols="12" md="6">
<h5>Image left</h5>
<b-card no-body img-left>
<b-skeleton-img card-img="left" width="225px"></b-skeleton-img>
<b-card-body>
Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis
egestas. Phasellus at consequat dui.
</b-card-body>
</b-card>
</b-col>
<b-col cols="12" md="6">
<h5>Image right</h5>
<b-card no-body img-right>
<b-skeleton-img card-img="right" width="225px"></b-skeleton-img>
<b-card-body>
Aenean tristique sagittis quam, sit amet sollicitudin neque sodales in.
</b-card-body>
</b-card>
</b-col>
</b-row>
アイコン
<b-skeleton-icon>
は、アイコンのプレースホルダーとしても使用できます。アイコンのプロップを使用する必要がある場合は、icon-props
プロパティを介して渡すことができます。
<b-skeleton-icon
icon="person"
:icon-props="{ fontScale: 2 }"
></b-skeleton-icon>
<b-skeleton-icon
icon="person-fill"
:icon-props="{ fontScale: 2, variant: 'dark' }"
></b-skeleton-icon>
注記:throb
アニメーションは b-skeleton-icon
では機能しません。
スタイルとカスタマイズ
<b-skeleton>
コンポーネントとヘルパーコンポーネントは、可能な限りBootstrap SCSS変数を使用し、ネイティブコンポーネントのスタイルとサイズに最適に一致させます。つまり、Bootstrap SCSSをカスタマイズした場合、スケルトンコンポーネントはカスタムテーマに合わせて調整されます。
また、様々な<b-skeleton>
コンポーネントのスタイルをさらにカスタマイズするために使用できる、いくつかのカスタムSCSS変数も用意しています。これらの変数の変更方法の詳細については、テーマセクションを参照してください。