以下是修改后的代码:
<view class="flex flex-direction">
<button class="cu-btn lg margin-tb-sm"
:class="isRecording ? 'bg-red' : 'bg-blue'"
@touchstart="handleTouchStart"
@touchend="stopRecording"
style="height: 80px;">
<text class="cuIcon-voice"></text>
{{isRecording ? '松开结束' : '按住不放开始'}}
</button>
</view> 然后在你的JavaScript/Vue方法部分添加以下代码:
data() {
return {
isRecording: false,
lastTouchTime: 0,
touchThreshold: 300 // 设置触发间隔阈值,单位毫秒
}
},
methods: {
handleTouchStart(e) {
const now = Date.now();
// 检查距离上次触发的时间是否超过阈值
if (now - this.lastTouchTime > this.touchThreshold) {
this.lastTouchTime = now;
this.startRecording(e);
}
},
startRecording(e) {
// 原来的录音开始逻辑
if (!this.isRecording) {
this.isRecording = true;
// 其他录音开始代码...
}
},
stopRecording(e) {
// 录音结束逻辑
if (this.isRecording) {
this.isRecording = false;
// 其他录音结束代码...
}
}
} 解决方案说明添加了一个新的方法 handleTouchStart 来处理 touchstart 事件使用时间戳来跟踪上次触发的时间设置了一个阈值(这里是300毫秒),只有当两次触发的间隔大于这个阈值时,才会真正执行录音开始的逻辑这样可以有效防止用户快速点击导致的多次触发问题你可以根据实际需求调整 touchThreshold 的值,使其更适合你的应用场景。
网友回复
如何修改别人发给我的微信笔记内容?
fbx、obj、glb三维格式模型如何在浏览器中通过three相互转换格式?
python如何实现基于http隧道加密的正向代理服务?
有没有有专门针对 UI 界面截图进行智能标记(Set-of-Mark, SoM) 的开源库和工具?
如何用python实现Set-of-Mark (SoM) 技术?
python如何截取windows指定应用的窗口截图,不用管窗口是不是在最前面?
linux能不能给rm删除命令增加回收站功能,可恢复被删文件?
bfwsoa如何在命令行中执行控制器动作器方法?
RAG(检索增强生成)和 KG(知识图谱)有啥不同?
KVM硬件是啥?


