【发布时间】:2020-12-11 13:15:30
【问题描述】:
我是 VueJS 的新手,我来找你看看我所做的是否可行。
在加载组件时,我更喜欢显示预加载器,而不是旧数据。 我喜欢骨架加载器的想法,而不是简单的微调器。
现在我在 store 中有一个 state,默认为 null,我有一个用于设置加载的突变和一个 getter。 为了避免视觉错误,从路由器开始,我使用 beforeEach 将加载状态初始化为 true,以便默认情况下组件开始加载!
然后,在我看来,我导入了 Loader 组件及其 svg 和样式。 我把它放在需要显示的组件上,条件很简单 v-if="!getLoading" 和 v-if="getLoading"。
问题是我觉得我在修补百叶窗、beforeach 并用条件显示这个组件?
如果有人能给我一些建议,或者批准这种做法,我会很放心!
这是一个简单的Loader组件的代码
<template>
<content-loader
:height="78"
:width="390"
:speed="4"
primaryColor="#f2f6fe"
secondaryColor="#e0eafa"
>
<rect x="9" y="20" rx="4" ry="4" width="142" height="13" />
<rect x="316.38" y="5.38" rx="5" ry="5" width="68" height="68" />
<rect x="9" y="46" rx="4" ry="4" width="75.26" height="13.26" />
</content-loader>
</template>
<script>
import { ContentLoader } from "vue-content-loader"
export default {
components: {
ContentLoader
}
}
</script>
商店代码
const state = {
loading: null,
}
const mutations = {
SET_LOADING: (state, payload) => {
state.loading = payload;
},
}
const getters = {
getLoading(state) {
return state.loading;
}
}
我认为的使用示例:有条件
<div class="col-12 col-lg-4 col-xl-3 col-md-6" v-if="getLoading"> // the condition
<div class="card animate-up-2">
<div class="card-body">
// the component
<StatsLoader></StatsLoader>
</div>
</div>
</div>
<div class="col-12 col-lg-4 col-xl-3 col-md-6" v-if="!getLoading"> // the condition
<div class="card animate-up-2">
<div class="card-body">
<div class="d-flex align-items-center justify-content-between">
<div>
<h3 class="font-weight-bold text-uppercase">5 %</h3>
<div class="d-flex d-sm-block d-lg-flex align-items-end">
<p class="mb-0 mr-2 text-muted">API usage</p>
</div>
</div>
<div>
<div class="avatar avatar-lg">
<div class="avatar-title sred sbg-soft-red rounded">
<i class="fad fa-project-diagram"></i>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
【问题讨论】:
标签: javascript vue.js