vue 全局loading的思路和方法
Vue 全局 loading 的实现思路一般是在 Vue 实例中添加一个 loading 组件,通过控制该组件的显示和隐藏来实现全局 loading 的效果。
具体思路如下:
- 创建一个全局的 Vue 组件 Loading,该组件用于显示 loading 状态。
<template>
<div class="loader" v-show="visible">
<div class="inner one"></div>
<div class="inner two"></div>
<div class="inner three"></div>
<!-- <p class="loader_text">加载中... ...</p> -->
</div>
</template>
<script>
export default {
data() {
return {
// visible: false,
};
},
props: {
visible: Boolean,
},
methods: {
// show() {
// console.log("显示loading");
// this.visible = true;
// },
// hide() {
// console.log("隐藏loading");
// this.visible = false;
// },
},
mounted() {
this.$nextTick(() => {
this.visible = false;
});
},
};
</script>
<style scoped>
.loader {
position: fixed;
top: calc(50% - 150px);
left: calc(50% - 82px);
width: 164px;
height: 164px;
border-radius: 50%;
perspective: 800px;
}
.inner {
position: absolute;
box-sizing: border-box;
width: 100%;
height: 100%;
border-radius: 50%;
}
.inner.one {
left: 0%;
top: 0%;
animation: rotate-one 1.4s linear infinite;
border-bottom: 6px solid #0060ca;
}
.inner.two {
right: 0%;
top: 0%;
animation: rotate-two 1.4s linear infinite;
border-right: 6px solid #ffbf00;
}
.inner.three {
right: 0%;
bottom: 0%;
animation: rotate-three 1.4s linear infinite;
border-top: 6px solid #29dcf1;
}
@keyframes rotate-one {
0% {
transform: rotateX(35deg) rotateY(-45deg) rotateZ(0deg);
}
100% {
transform: rotateX(35deg) rotateY(-45deg) rotateZ(360deg);
}
}
@keyframes rotate-two {
0% {
transform: rotateX(50deg) rotateY(10deg) rotateZ(0deg);
}
100% {
transform: rotateX(50deg) rotateY(10deg) rotateZ(360deg);
}
}
@keyframes rotate-three {
0% {
transform: rotateX(35deg) rotateY(55deg) rotateZ(0deg);
}
100% {
transform: rotateX(35deg) rotateY(55deg) rotateZ(360deg);
}
}
.loader_text {
font-size: 25px;
color: #0060ca;
text-align: center;
padding-top: 190px;
}
</style>
- 创建一个js文件 loading.js
import Vue from "vue";
import componentLoading from "../../components/overallLoading";
const comLoading = Vue.extend(componentLoading);
const instance = new comLoading({
el: document.createElement("div"),
});
instance.visible = false;
const loading = {
show() {
instance.visible = true;
document.body.appendChild(instance.$el);
},
hide() {
instance.visible = false;
},
};
export default {
install() {
if (!Vue.$loading) {
Vue.$loading = loading;
}
Vue.mixin({
created() {
this.$loading = Vue.$loading;
},
});
},
};
- 在 main.js 中注册 Loading 组件,并挂载到 Vue 实例上。
// 全局引入loading
import loadong from "./assets/js/loading";
Vue.use(loadong);
new Vue({
el: '#app',
render: h => h(App)
});
在需要显示 loading 的地方,调用全局方法 $loading.show(),该方法通过修改 loading 组件的状态来显示 loading。
在需要隐藏 loading 的地方,调用全局方法 $loading.hide(),该方法通过修改 loading 组件的状态来隐藏 loading。
全局使用:
this.$loading.show();
this.$loading.hide();
这篇好文章是转载于:学新通技术网
- 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
- 本站站名: 学新通技术网
- 本文地址: /boutique/detail/tanhggcajk
系列文章
更多
同类精品
更多
-
photoshop保存的图片太大微信发不了怎么办
PHP中文网 06-15 -
《学习通》视频自动暂停处理方法
HelloWorld317 07-05 -
word里面弄一个表格后上面的标题会跑到下面怎么办
PHP中文网 06-20 -
Android 11 保存文件到外部存储,并分享文件
Luke 10-12 -
photoshop扩展功能面板显示灰色怎么办
PHP中文网 06-14 -
微信公众号没有声音提示怎么办
PHP中文网 03-31 -
excel下划线不显示怎么办
PHP中文网 06-23 -
excel打印预览压线压字怎么办
PHP中文网 06-22 -
TikTok加速器哪个好免费的TK加速器推荐
TK小达人 10-01 -
怎样阻止微信小程序自动打开
PHP中文网 06-13