2023/3/1 uni-app自定义loading
1.在components 里面创建loading.vue
-
<template>
-
<view v-show="loadingShow">
-
<view class="request-loading-view">
-
<view class="loading-view"><view class="loading"></view></view>
-
</view>
-
</view>
-
</template>
-
<script>
-
export default {
-
data() {
-
return {};
-
},
-
computed: {
-
//计算属性判断vuex中的显示状态
-
loadingShow() {
-
return this.$store.state.loading.requestLoading;
-
}
-
}
-
};
-
</script>
-
-
<style scoped>
-
.request-loading-view {
-
position: fixed;
-
top: 0;
-
left: 0;
-
width: 100%;
-
height: 100%;
-
z-index: 10000;
-
background-color: rgba(0, 0, 0, 0.001);
-
display: flex;
-
justify-content: center;
-
align-items: center;
-
}
-
.loading-view {
-
width: 160upx;
-
height: 160upx;
-
background-color: rgba(0, 0, 0, 0.6);
-
border-radius: 20upx;
-
display: flex;
-
justify-content: center;
-
align-items: center;
-
}
-
-
/* 动画样式 */
-
.loading {
-
border: 10upx solid rgba(0, 0, 0, 0.01);
-
border-radius: 50%;
-
border-top: 10upx solid #fff;
-
border-right: 10upx solid #fff;
-
border-bottom: 10upx solid #fff;
-
width: 60upx;
-
height: 60upx;
-
-webkit-animation: spin 1.4s linear infinite;
-
animation: spin 1.4s linear infinite;
-
}
-
-
@-webkit-keyframes spin {
-
0% {
-
-webkit-transform: rotate(0deg);
-
}
-
-
100% {
-
-webkit-transform: rotate(360deg);
-
}
-
}
-
-
@keyframes spin {
-
0% {
-
transform: rotate(0deg);
-
}
-
-
100% {
-
transform: rotate(360deg);
-
}
-
}
-
</style>
2.加载vuex在里面定义变量控制是否显示隐藏
-
-
const state = {
-
requestLoading: false, //加载等待是否显示
-
}
-
-
-
const mutations = {
-
-
//显示请求加载动画
-
requestShowLoading(state) {
-
state.requestLoading = true;
-
},
-
//隐藏请求加载动画
-
requestHideLoading(state) {
-
state.requestLoading = false;
-
},
-
}
-
-
export default {
-
namespaced: true,
-
state,
-
mutations,
-
}
3.在main.js里面导入组件和定义方法
-
-
//请求加载组件
-
import tLoading from '@/components/loading/loading.vue';
-
-
// 在main.js中注册全局组件
-
Vue.prototype.$store = store
-
-
//组件挂载到全局,方便每个页面使用
-
Vue.component('Loading', Loading);
-
-
//挂载全局显示/隐藏请求加载动画
-
function requestShowLoading(){
-
this.$store.commit('ShowLoading');
-
}
-
function requestHideLoading(){
-
this.$store.commit('HideLoading');
-
}
-
Vue.prototype.$showLoading = ShowLoading; //全局显示动画可以 this.$showLoading();
-
Vue.prototype.$hideLoading = HideLoading; //全局隐藏动画可以 this.$hideLoading();
4.在需要的页面使用Loading
-
例如:home.vue
-
-
<view>
-
<!-- loading -->
-
<Loading></Loading>
-
</view>
-
-
onLoad() {
-
this.$showLoading();
-
数据加载完之后
-
that.$hideLoading();
-
},
这篇好文章是转载于:学新通技术网
- 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
- 本站站名: 学新通技术网
- 本文地址: /boutique/detail/tanhgbcgch
系列文章
更多
同类精品
更多
-
photoshop保存的图片太大微信发不了怎么办
PHP中文网 06-15 -
Android 11 保存文件到外部存储,并分享文件
Luke 10-12 -
word里面弄一个表格后上面的标题会跑到下面怎么办
PHP中文网 06-20 -
《学习通》视频自动暂停处理方法
HelloWorld317 07-05 -
photoshop扩展功能面板显示灰色怎么办
PHP中文网 06-14 -
微信公众号没有声音提示怎么办
PHP中文网 03-31 -
excel下划线不显示怎么办
PHP中文网 06-23 -
怎样阻止微信小程序自动打开
PHP中文网 06-13 -
excel打印预览压线压字怎么办
PHP中文网 06-22 -
TikTok加速器哪个好免费的TK加速器推荐
TK小达人 10-01