el-input+vue+ts防抖处理

el-input+vue+ts防抖处理

<el-input  @input="debounce()" ></el-input>

// 防抖处理
private timer: any = '';

private debounce(data?: any) {
    const _this: any = this;
    if (this.timer) {
      clearTimeout(this.timer)
    }
    this.timer = setTimeout(function() {
      // 写你需要防抖处理的事件
      // console.log('输入')
      _this.timer = undefined;
    }, 1000);
  }
//节流
<div  @click="throttle()" >点击点击</div>
 
 private timer: any = ''
 private lastTime: any = ''
 
 private throttle() {
    const _this: any = this;
    let now = +new Date()
    if (this.lastTime && this.lastTime - now < 2000) {
      clearTimeout(this.timer)
    }
    this.timer = setTimeout(function() {
      console.log('点击')
      _this.lastTime = +new Date()
    }, 200)
  }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Vue中,你可以结合`element-ui`的`el-upload`组件和`vue-cropper`库来实现图片上传和裁剪功能。以下是一个基本的步骤: 1. 安装依赖: 首先,你需要安装这两个库,如果你还没有安装,可以在项目目录下运行: ```bash npm install element-ui vue-cropper ``` 2. 引入组件: 在你的Vue文件中,引入这两个组件: ```javascript import { ElUpload } from 'element-ui'; import VueCropper from 'vue-cropper'; ``` 3. 在模板中使用`el-upload`和`vue-cropper`: ```html <template> <div> <el-upload :action="uploadUrl" :on-success="handleSuccess" :on-change="handleChange" :before-upload="beforeUpload" ref="upload" > <el-button size="small" type="primary">点击选择图片</el-button> </el-upload> <vue-cropper ref="cropper" :img-url="croppedImageUrl" :output-type="outputType"></vue-cropper> </div> </template> ``` 4. 编写方法: - `handleSuccess(response, file)`:处理上传成功后的回调,这里可以更新`croppedImageUrl`。 - `handleChange(file)`:处理文件变化,可以预览图片并显示到cropper组件中。 - `beforeUpload(file)`:在上传前的钩子,可以在这里做些验证或处理。 5. 数据绑定: ```javascript data() { return { uploadUrl: 'your-upload-url', croppedImageUrl: '', outputType: 'image/jpeg', // 可选类型:image/jpeg, image/png, image/webp }; }, methods: { handleSuccess(response, file) { // 在这里处理上传成功的响应并更新croppedImageUrl this.croppedImageUrl = response.data.url; }, handleChange(file) { this.$refs.upload.fileList = file; // 将文件信息传递给cropper this.$refs.cropper.src = file.url; // 设置cropper的图片源 }, beforeUpload(file) { // 这里可以根据需求检查文件大小、类型等 } } ``` 注意替换`your-upload-url`为你实际的图片上传地址。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值