建站公司上海,各大引擎搜索入口,后台网站更新 网站没显示,东莞公司网站建设公司哪家好1、业务需求
需要加一个按钮#xff0c;调用第三方API#xff0c;按钮十分钟之内只能点击一次#xff0c;刷新页面也只能点击一次
2、思路
加一个本地缓存的时间戳#xff0c;通过时间戳计算指定时间内不能点击按钮
3、实现
1#xff09;vue页面
template调用第三方API按钮十分钟之内只能点击一次刷新页面也只能点击一次
2、思路
加一个本地缓存的时间戳通过时间戳计算指定时间内不能点击按钮
3、实现
1vue页面
templateel-row :gutter15el-col :span4el-buttontypedangericonel-icon-download clickgetData:loadinggetDataLoading获取数据/el-button/el-col/el-row
/templatescript typetext/ecmascript-6
import { GetDataInfo } from /api/xxxexport default {data () {return {getDataLoading: false,}},methods: {// 获取数据按钮10分钟内执行一次(本地缓存)async getData () {const storedTime localStorage.getItem(lastClickGetDataTime) const currentTime Date.now() // 时间戳(秒级)if (!storedTime || (currentTime - storedTime) / 1000 / 60 10) {// 如果存储的时间不存在或者距离上次点击时间超过10分钟则执行按钮点击操作 this.getDataLoading truetry {await GetDataInfo({})} catch (error) {this.getDataLoading false}this.getDataLoading falselocalStorage.setItem(lastClickGetDataTime, currentTime) } else { // 距离上次点击时间小于10分钟不做任何操作或给出提示 this.$message({ message: 请在十分钟后再点击按钮, type: warning,})}},},
}
/script// 注指定时间可以根据需要更新比如1分钟内只能点击一次只需要将循环部分改为 if (!storedTime || (currentTime - storedTime) / 1000 60) 2 效果 希望以上内容能够帮助你使用Vue Element 实现按钮指定间隔时间点击。欢迎点赞、关注、收藏如果你还有其他问题欢迎评论区交流。