vue中使用箭头控制input的焦点 适合操作大量表格填写

首先老样子 下载包

yarn add vue-direction-key

然后在全局引用或者组件 都行

// 引入控制input焦点插件
import Direction from 'vue-direction-key'
Vue.use(Direction)

然后是在组件中填写

<el-table
                    :data="tableData"
                    style="width: 100%">
                    <el-table-column
                        prop="code"
                        label="生物编码"
                        width="180">
                        <template slot-scope="scope">
                            <span>{{scope.row.code}}</span>
                        </template>
                    </el-table-column>
                    <el-table-column
                        prop="oldEar"
                        label="原耳号"
                        width="180">
                        <template slot-scope="scope">
                            <span>{{scope.row.oldEar}}</span>
                        </template>
                    </el-table-column>
                    <el-table-column
                        prop="area"
                        label="场地"
                        width="180">
                        <template slot-scope="scope">
                            <span>{{scope.row.area}}</span>
                        </template>
                    </el-table-column>
                    <el-table-column
                        prop="newEar"
                        label="现耳号"
                        width="180">
                        <template slot-scope="scope">
                            <el-input v-model="scope.row.newEar" placeholder="请输入内容" v-direction="{x: 1, y: scope.$index}" ></el-input>
                        </template>
                    </el-table-column>
                    <el-table-column
                        prop="firstTimeWeight"
                        label="初生重"
                        width="180">
                        <template slot-scope="scope">
                            <el-input v-model="scope.row.firstTimeWeight" placeholder="请输入内容" v-direction="{x: 2, y: scope.$index}"></el-input>
                        </template>
                    </el-table-column>
                    <el-table-column
                        prop="motherEar"
                        label="母系普通耳标"
                        width="180">
                        <template slot-scope="scope">
                            <el-input v-model="scope.row.motherEar" placeholder="请输入内容" v-direction="{x: 3, y: scope.$index}"></el-input>
                        </template>
                    </el-table-column>
                    <el-table-column
                        prop="fatherEar"
                        label="父系普通耳标"
                        width="180">
                        <template slot-scope="scope">
                            <el-input v-model="scope.row.fatherEar" placeholder="请输入内容" v-direction="{x: 4, y: scope.$index}"></el-input>
                        </template>
                    </el-table-column>
                    <el-table-column
                        prop="allNum"
                        label="同胞数">
                        <template slot-scope="scope">
                            <el-input v-model="scope.row.allNum" placeholder="请输入内容" v-direction="{x: 5, y: scope.$index}"></el-input>
                        </template>
                    </el-table-column>
                    <el-table-column
                        prop="grace"
                        label="生物等级">
                        <template slot-scope="scope">
                            <el-select v-model="scope.row.grace" placeholder="请选择">
                                <el-option
                                    v-for="items in scope.row.nameGrace"
                                    :key="items.id"
                                    :label="items.name"
                                    :value="items.name">
                                </el-option>
                            </el-select>
                        </template>
                    </el-table-column>
                </el-table>

在created()中写

const direction = this.$getDirection()
        direction.on('keyup', function(e, val) {
            console.log(val)
            if (e.keyCode === 39) {
                direction.next()
            }
            if (e.keyCode === 37) {
                direction.previous()
            }
            if (e.keyCode === 38) {
                direction.previousLine()
            }
            if (e.keyCode === 40) {
                direction.nextLine()
            }
        })

可以随便写什么按钮 只要对应的keyCode
再附带数据

//纯手工mock数据
tableData: [{
                code: '001',
                date: '2016-05-04',
                oldEar: '王小虎1',
                area: '上海市普陀区金沙江路 1519 弄',
                newEar: '王小龙6',
                grace: '',
                firstTimeWeight: 300,
                motherEar: 'm002341',
                fatherEar: 'f001',
                allNum: 8,
                nameGrace: [{
                    id: 1,
                    name: '小毛'
                }, {
                    id: 5,
                    name: 'huazi'
                }]
            }, {
                code: '002',
                date: '2016-05-06',
                oldEar: '王小虎2',
                area: '上海市普陀区金沙江路 1520 弄',
                newEar: '王小龙7',
                grace: '',
                firstTimeWeight: 1,
                motherEar: 'm001',
                fatherEar: 'f02301',
                allNum: 134,
                nameGrace: [{
                    id: 2,
                    name: '小李'
                }]
            }, {
                code: '003',
                date: '2016-05-08',
                oldEar: '王小虎3',
                area: '上海市普陀区金沙江路 1521 弄',
                newEar: '王小龙8',
                grace: '',
                firstTimeWeight: 12314,
                motherEar: 'm02201',
                fatherEar: 'f02301',
                allNum: 2,
                nameGrace: [{
                    id: 3,
                    name: '小冲'
                }]
            }, {
                code: '004',
                date: '2016-05-10',
                oldEar: '王小虎4',
                area: '上海市普陀区金沙江路 1522 弄',
                newEar: '王小龙9',
                grace: '',
                firstTimeWeight: 188,
                motherEar: 'm01101',
                fatherEar: 'f0401',
                allNum: 82,
                nameGrace: [{
                    id: 4,
                    name: '小点'
                }]
            }],
            // mock结束

焦点只会在input里面跳转

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值