vuejs2 - 在 vue.js 中设置 el-input 和 el-select 行数组元素的焦点?
问题描述
我有按元素设置焦点行数组的问题我不知道为什么我不能像下面的代码和图片那样设置焦点。我按元素本身单击单元格行。请推荐并解决我的问题。
//Template
<!-- Qty -->
<el-table-column
v-if="showActiveHeader('qty')"
prop="qty"
label="Qty"
>
<template slot-scope="scope">
<el-form-item
v-if="scope.$index === activeRowIndex"
:key="scope.$index + '.qty'"
:prop="'items.' + scope.$index + '.qty'"
:rules="rules.qty"
class="form-item"
style="margin:0"
>
<el-input-number
ref="Qty"
v-model="scope.row.qty"
:precision="decimalNumber"
:controls="false"
:size="formSize"
:min="minQty"
style="width:100%"
@change="rowChange(scope.row, 'Qty')"
/>
</el-tooltip>
</el-form-item>
<span v-else>
{{ scope.row.qty | number }}
</span>
</template>
</el-table-column>
<!-- Unit -->
<el-table-column
v-if="showActiveHeader('unit')"
prop="unitId"
label="Unit"
>
<template slot-scope="scope">
<el-form-item
v-if="scope.$index === activeRowIndex"
:key="scope.$index + '.unitId'"
:prop="'items.' + scope.$index + '.unitId'"
:rules="rules.unitId"
class="form-item"
style="margin:0"
>
<el-select
ref="Unit"
v-model="scope.row.unitId"
automatic-dropdown
:size="formSize"
filterable
@change="rowChange(scope.row, 'Unit')"
>
<el-option
v-for="doc in scope.row.units"
:key="doc.unitId"
:label="doc.unitDoc.name"
:value="doc.unitId"
:disabled="doc.disabled"
/>
</el-select>
</el-form-item>
<span v-else>
{{ scope.row.unitLabel }}
</span>
</template>
</el-table-column>
//vue js
handleCellClick(row, column) {
this.activeRowIndex = this.form.items.indexOf(row)
this.$nextTick(() => {
let label = column.label
this.$refs[label].focus()
})
}
我尝试this.$els.nameInput.focus();
了我可以在网上找到的东西来定位焦点,但this.$els
没有奏效。
解决方案
v-el 在 vue2 中被替换/合并为 ref,尝试使用 $refs 而不是 $els
https://vuejs.org/v2/guide/migration.html#v-el-and-v-ref-replaced
推荐阅读
- ubuntu - 未找到 RabbitMQ 3.7.8 AWS 集群形成插件
- typescript - 在 WebStorm 2018 中启动 TypeScript 语言服务时出错
- python - 使用 pyInstaller 时缺少模块
- sql-server - SQL:比较来自两个不同选择的两个结果
- javascript - node.js next() 中间件函数如何在没有参数的情况下工作?
- asp.net-mvc - MVC 可选主体参数
- javascript - php和bootstrap在action post中传递值
- mysql - 计算(My)Sql 一对多关系中的基本记录数量
- c# - OpenXML C# 中的嵌套表可能吗?
- pandas - 有条件的数据透视表