setInterval 设置定时器

  • HTML
<button type="file" :class="{sent:sent}" @click="uploadImg">{{uploadImgTitle}}</button>
  • data
data(){
    uploadImgTitle:"上传图片"
}
  • JS
var _this = this
if((_this.sourceImg.length>0) && (_this.uploadImgTitle == '上传图片')){
	let time = 60;
	let setTime = setInterval(function(){
	time = time - 1
     if(time > 0){
	    _this.uploadImgTitle = time + '秒后可点击重新上传'
	} else {
	  clearInterval(setTime)
	  _this.uploadImgTitle = '上传图片'
	  time = 60
	}
    },1000)	
} else {
	uni.showToast({
     title:'请至少选择一张图片',
	duration:1500
})				

  附上效果图:

                 before

 

                  after

 

posted @ 2021-01-14 10:40  SpongGirl  阅读(140)  评论(0)    收藏  举报