Vue.directive('focus', {
// 当被绑定的元素插入到 DOM 中时……
bind: function (el,binding,vnode,oldVnode) {
// 聚焦元素
el.style.color = 'red'
el.style.fontSize = '28px'
el.addEventListener('mousewheel',function (e){
console.log(e.wheelDelta)
el.innerHTML = e.wheelDelta
})
el.__timeout__ = setInterval(() => {
el.innerHTML = binding.value ++
}, 1000)
},
unbind(el) {
console.log("🚀 ~ file: main.js:92 ~ unbind ~ el:", el)
clearInterval(el.innerHTML)
}
})
<template>
<div class="welcome">
<!-- <img src="@/assets/image/welcome.png" alt=""> -->
<div v-focus="mousewheel" >input</div>
</div>
</template>
<script>
export default {
name: 'welcome',
data() {
return {
mousewheel: 1565753400000
}
},
// directives: {
// focus: {
// // 指令的定义
// inserted: function (el) {
// el.focus()
// }
// }
// }
}