项目中使用到了高德地图,threejs绘制地图,其中有一些数据配置使用到了el-input-number,展示了控件。 操作过程中,点击 +-号,频频不生效
解决过程
1.手动给+icon设置了点击事件,点击生效,没问题
2.change事件未同步icon的点击事件触发,why,为啥没触发呢
看了下el-input-number的源码,没有点击事件,有个v-repeat-click="decrease"
指令
ini
<span
class="el-input-number__decrease"
role="button"
v-if="controls"
v-repeat-click="decrease"
:class="{'is-disabled': minDisabled}"
@keydown.enter="decrease">
<i :class="`el-icon-${controlsAtRight ? 'arrow-down' : 'minus'}`"></i>
</span>
<span
class="el-input-number__increase"
role="button"
v-if="controls"
v-repeat-click="increase"
:class="{'is-disabled': maxDisabled}"
@keydown.enter="increase">
<i :class="`el-icon-${controlsAtRight ? 'arrow-up' : 'plus'}`"></i>
</span>
顺藤摸瓜看看指令啥效果,主要就是mousedown
事件,连续加,mouseup
清除了定时器,只有这个功能,不应该不生效呀
ini
import { once, on } from 'element-ui/src/utils/dom';
import { isMac } from 'element-ui/src/utils/util';
export default {
bind(el, binding, vnode) {
let interval = null;
let startTime;
const maxIntervals = isMac() ? 100 : 200;
const handler = () => vnode.context[binding.expression].apply();
const clear = () => {
if (Date.now() - startTime < maxIntervals) {
handler();
}
clearInterval(interval);
interval = null;
};
on(el, 'mousedown', (e) => {
if (e.button !== 0) return;
startTime = Date.now();
once(document, 'mouseup', clear);
clearInterval(interval);
interval = setInterval(handler, maxIntervals);
});
}
};
看页面控制台的verbose 有这个 [Violation] 'requestAnimationFrame' handler took 91ms
原来这个微任务的时间叠加了。
然后重新copy了组件,去掉了这个v-repeat-click="decrease
,加一下click函数。向element-ui 提了issue,配置长按累加/减功能,看有没有时间去改