uniapp 点击动画_uni-app自定义加载动画组件

先写好一个加载动画组件,如:

export default {

data() {

return {};

},

computed: {

//计算属性判断vuex中的显示状态

loadingShow() {

return this.$store.state.requestLoading;

}

}

};

.request-loading-view {

position: fixed;

top: 0;

left: 0;

width: 100%;

height: 100%;

z-index: 198903060;

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);

}

}

main.js 中添加相应引用,使用Vuex来记录显示状态,所以Vuex也需要引用

//Vuex

import store from './store'

Vue.prototype.$store = store

//请求加载组件

import requestLoading from './components/compt_requestLoading.vue';

//组件挂载到全局,方便每个页面使用

Vue.component('request-loading', requestLoading);

//挂载全局显示/隐藏请求加载动画

function showLoading(){

store.commit('request_show_loading');

}

function hideLoading(){

store.commit('request_hide_loading');

}

Vue.prototype.$showLoading = showLoading; //全局显示动画可以 this.$showLoading();

Vue.prototype.$hideLoading = hideLoading; //全局隐藏动画可以 this.$hideLoading();

Vuex的store/index.js中这样写

//Vuex

import Vue from 'vue'

import Vuex from 'vuex'

Vue.use(Vuex)

const store = new Vuex.Store({

state: {

requestLoading: false //加载等待是否显示

},

mutations: {

//显示请求加载动画

request_show_loading(state) {

state.requestLoading = true;

},

//隐藏请求加载动画

request_hide_loading(state) {

state.requestLoading = false;

}

}

})

export default store

然后每个页面添加标签

即可

调用显示/隐藏可以直接

this.$showLoading()

this.$hideLoading()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值