vue+Element实现loading效果

loading效果

指令方式
// html中, 通过设置fullscreenLoading的状态来开启和关闭loading效果,可以在css中设置背景色的透明度
<el-button @click="openFullScreen1" v-loading.fullscreen.lock="fullscreenLoading">指令方式</el-button>
// data
data() {
	fullscreenLoading: false
}
//script
openFullScreen1() {
			this.fullscreenLoading = true;
			setTimeout(() => {
				this.fullscreenLoading = false;
			}, 2000);
		},
// css 
.el-loading-mask {
  background-color: rgba(255, 255, 255, 0.1) ;
}
服务方式
//html
<el-button type="primary" @click="openFullScreen2">
			服务方式
</el-button>
// script
openFullScreen2() {
				const loading = this.$loading({
					lock: true,
					text: '拼命加载中',// 修改显示文字
					spinner: 'el-icon-loading',//可以设置图标
					background: 'rgba(255, 255, 255, 0.9)'
				});
				setTimeout(() => {
					loading.close();
				}, 2000);
			},
下载外部插件

安装插件 npm install vue-element-loading --save

// 引用
import VueElementLoading from 'vue-element-loading'
components: {
			VueElementLoading
		},
// html
<vue-element-loading :active="isActive" spinner="bar-fade-scale" color="#FF6700" />
<el-button @click="toLoad">加载</el-button>
// data
data() {
	isActive: false,
}
// script
// 开启加载,设置时间关闭加载, 可以设置color改变图标的颜色
toLoad() {
				this.isActive = true
				setTimeout(() => {
					this.isActive = false
				}, 2000);
				console.log(this.isActive)
			},

效果:
在这里插入图片描述

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值