docs_vue2/one/docs/demo/directives/nudge.vue

77 lines
1.1 KiB
Vue
Raw Normal View History

2020-08-13 11:47:56 +08:00
<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'
2020-08-13 11:47:56 +08:00
export default {
directives: {
nudge
},
data () {
return {
value: 0
}
},
computed: {
displayValue () {
return this.value.toFixed(1).replace('.0', '')
}
},
methods: {
handleNudgeUpdate (increase) {
this.value += increase
}
}
}
</script>
2021-09-15 20:03:51 +08:00
<style lang="less" scoped>
2020-08-13 11:47:56 +08:00
article {
display: flex;
}
.box {
2021-09-15 20:03:51 +08:00
width: 200px;
height: 50px;
2020-08-13 11:47:56 +08:00
display: flex;
align-items: center;
justify-content: center;
2021-09-15 20:03:51 +08:00
border: 1px solid #dbdbdb;
2020-08-13 11:47:56 +08:00
background: #fff;
margin-right: 40px;
user-select: none;
cursor: pointer;
outline: none;
transition: background-color 0.3s;
line-height: 1;
&:focus {
2021-09-15 20:03:51 +08:00
background-color: #e7e7e7;
2020-08-13 11:47:56 +08:00
}
}
.value {
font-size: 1.5em;
}
</style>