v-nudge
The v-nudge directive is used to adjust values using directional keys on the keyboard.
Examples
 0 
 点我,按左右方向键 
 点我,按上下方向键 
<template>
<article>
  <div class="box value">
    {{ displayValue }}
  </div>
  <div
    v-nudge.x="{update: handleNudgeUpdate}"
    class="box"
    tabindex="-1"
  >
    点我,按<strong>左右</strong>方向键
  </div>
  <div
    v-nudge.y="{update: handleNudgeUpdate}"
    class="box"
    tabindex="-1"
  >
    点我,按<strong>上下</strong>方向键
  </div>
</article>
</template>
<script>
import { nudge } from 'veui'
export default {
  directives: {
    nudge
  },
  data () {
    return {
      value: 0
    }
  },
  computed: {
    displayValue () {
      return this.value.toFixed(1).replace('.0', '')
    }
  },
  methods: {
    handleNudgeUpdate (increase) {
      this.value += increase
    }
  }
}
</script>
<style lang="less" scoped>
article {
  display: flex;
}
.box {
  width: 200px;
  height: 50px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid #dbdbdb;
  background: #fff;
  margin-right: 40px;
  user-select: none;
  cursor: pointer;
  outline: none;
  transition: background-color 0.3s;
  line-height: 1;
  &:focus {
    background-color: #e7e7e7;
  }
}
.value {
  font-size: 1.5em;
}
</style>
API
Options
Type: function | Object.
When using the function type, the options represent the callback function triggered after the directional keys are pressed. For example:
<div tabindex="-1" v-nudge="update"></div>
When using the Object type, the options can fully configure all parameters. For example:
<div tabindex="-1" v-nudge="{
  step: 5,
  axis: 'y',
  update: increase
}"></div>
| Name | Type | Default | Description | 
|---|---|---|---|
axis | string | y | Restricts adjustment with only left and right or up and down directional keys. Optional value types: 'x' | 'y' | 
step | number | nudge.step | Step value. Can be globally configured. | 
update | function(delta: number) | function() {} | Triggered when the value changes, passing in the changed value. The parameter delta is the calculated numeric change. | 
Modifiers
Corresponding to the axis / step in the Object type binding value. For example:
<div tabindex="-1" v-nudge.x.2="{ update: delta => this.val += delta }"></div>
| Name | Description | 
|---|---|
x | Restricts adjustment with only left and right directional keys. | 
y | Restricts adjustment with only up and down directional keys. | 
| step | The step value, note that step is a variable here. | 
Configs
| Key | Type | Default | Description | 
|---|---|---|---|
nudge.step | number | 1 | Step value. |