<MButton @click="output">button</MButton>
...
<template>
<button @click="handleClick">
<slot></slot>
</button>
</template>
<script lang="ts">
import { defineComponent, reactive, toRefs, watch, computed } from 'vue'
export default defineComponent({
name: 'MButton',
emits: {
click: null
},
setup(props, { attrs, emit }) {
const throttle = (fn: string, delay: number = 500) => {
let timer: number = null
return (...args: []) => {
if (!timer) {
emit(fn, args)
timer = window.setTimeout(() => {
timer = null
}, delay)
}
}
}
function handleClick() {
// emit('click')
throttle('click', 500)
}
return {
handleClick,
}
},
})
</script>
像这样写似乎无法触发
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…