为箭头绑定绑定键盘方向键
<div class="toggle-nav">
<span
v-if="leftToggleSt"
@click="toggleGoods(1)"
@keyup.left="toggleGoods(1)"
class="toggle-left"
>
<a-icon type="left" class="icon" />
</span>
<span
v-if="rightToggleSt"
@click="toggleGoods(2)"
@keyup.right="toggleGoods(2)"
tabindex="0"
class="toggle-right"
>
<a-icon type="right" class="icon" />
</span>
</div>
created() {
const self = this;
document.onkeyup = function(e) {
if (e.key == "ArrowLeft" || e.key == "ArrowUp") {
self.toggleGoods(1);
} else if (e.key == "ArrowRight" || e.key == "ArrowDown") {
self.toggleGoods(2);
}
}
},
methods:{
toggleGoods(){}
}
键盘上各按键对应的英文名