1. 自适应高度 v-autoComputedHeight
Vue.directive('autoComputedHeight', {
inserted(el, bind) {
if (bind.value) {
const scale = 375
const designHeight = bind.value
const screenWidth = document.documentElement.clientWidth
const result = designHeight * ( screenWidth / scale)
el.style = `height: ${result}px`
}
}
})
2. 防重复点击 v-preventReClick
Vue.directive('preventReClick', {
inserted (el, bind) {
el.addEventListener('click', () => {
if (!el.disabled) {
el.disabled = true
setTimeout(() => {
el.disabled = false
}, bind.value || 3000)
}
})
}
})