vue旋转图标

需求是当我们点击图标进行请求数据的时候,图标进行旋转,成功之后停止旋转,请求超时也会自动停止旋转

<div class="refresh" icon="el-icon-refresh" @click="refresh()">
	<img src="../assets/img/refresh.png" :class="[isRotate?'rotate':'rotate1']" style="border-radius: 50%;width: 100%;" />
</div>

js

data() {
	return {
		isRotate: false, //旋转图标
	}
},


//点击事件
refresh() {
    //点击的时候为true
	this.isRotate = true;
	axios.get(global.globalApi() + '/users')
		.then((res) => {
			if(res.status == 200) {
			    //成功之后为true
				this.isRotate = false
			}
		})
		.catch((err) => {
				//失败之后也为true
				this.isRotate = false; 
		});
},

css

.refresh {
	position: absolute;
	left: 50%;
	bottom: 4px;
	transform: translateX(-50%);
	cursor: pointer;
	width: 40px;
	height: 40px;
	border-radius: 50%;
	text-align: center;
	line-height: 40px;
	background: #fff;
	box-shadow: 0px 1px 10px 3px #eaeaea;
}
.rotate {
	animation: mymove 1s infinite;
	-webkit-animation: mymove 1s infinite;
}

@keyframes mymove {
	from {
		transform: rotate(0deg);
	}
	to {
		transform: rotate(360deg);
	}
}

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
1. 安装iconfont图标库 首先需要在iconfont官网下载需要使用的图标库,并将其导入到项目中。这里以阿里巴巴矢量图标库为例,下载完成后会得到一个名为“iconfont”的文件夹,将其复制到项目的public目录下。 2. 在main.js中引入iconfont图标库 在main.js中,我们需要引入iconfont图标库并将其挂载到Vue实例中。具体代码如下: ``` import Vue from 'vue'; import App from './App.vue'; import './public/iconfont/iconfont.css'; // 引入iconfont图标Vue.config.productionTip = false; new Vue({ render: h => h(App), }).$mount('#app'); ``` 3. 在vue组件中使用iconfont图标vue组件中使用iconfont图标需要先在html中创建一个标签,然后将需要使用的图标类名赋值给该标签的class属性。 例如,我们需要使用阿里巴巴矢量图标库中的“搜索”图标,其类名为“icon-search”,则在vue组件中使用该图标的代码如下: ``` <template> <div> <i class="iconfont icon-search"></i> </div> </template> ``` 注意,由于使用了iconfont图标库,需要将该标签设置为“i”标签。同时,需要将图标的类名添加到“class”属性中。 4. 样式调整 使用iconfont图标时,可以通过修改css样式来调整图标的大小、颜色、旋转等。 例如,要将搜索图标的大小调整为30px,颜色调整为红色,代码如下: ``` <template> <div> <i class="iconfont icon-search" style="font-size: 30px; color: red;"></i> </div> </template> ``` 通过在标签内部添加style属性,可以直接对图标进行样式调整。 以上就是在vue中使用iconfont图标的方法。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值