[英]Vue.js Input field loses focus after entry of one character
My vue.js-bound input box loses its focus after any keypress.我的 vue.js 绑定输入框在任何按键后都会失去焦点。 I found this similar question, but it doesn't really help me, as I don't use any keys.
我发现了这个类似的问题,但它并没有真正帮助我,因为我不使用任何键。 Here's my template code:
这是我的模板代码:
<DxColumn data-field="width"
caption="Spaltenbreite"
:allowEditing="false"
cell-template="width-settings" />
<!-- ... -->
<template #width-settings="cell">
<div>
<CSwitch :checked.sync="cell.data.data.width.set" size="sm" color="success" />
<div class="input-group input-group-sm" v-if="cell.data.data.width.set">
<input type="text" v-model="cell.data.data.width.width" class="form-control text-right" placeholder="auto" />
<select v-model="cell.data.data.width.unit" class="input-group-append custom-select custom-select-sm">
<option value="">Bitte wählen</option>
<option value="DEL">Nicht festlegen</option>
<optgroup label="Absolute Einheiten">
<option value="cm">Zentimeter</option>
<option value="mm">Millimeter</option>
<option value="in">Zoll</option>
<option value="px">Pixel</option>
</optgroup>
<optgroup label="Relative Einheiten">
<option value="em">-fache der Schriftgröße</option>
<option value="%">% des Bildschirms</option>
</optgroup>
</select>
</div>
</div>
</template>
This is part of a DevExtreme dxDataGrid cell definition.这是 DevExtreme dxDataGrid 单元定义的一部分。 How can I prevent the field from losing it's focus every time?
如何防止该领域每次都失去焦点?
It's a bit hard to tell what is going on with this code only , so I'm going to take a guess.仅使用此代码很难判断发生了什么,所以我要猜测一下。
I see the input has v-model="cell.data.data.width.width"
and a parent has v-if="cell.data.data.width.set"
while that shouldn't cause issues, and it may be possible that there may be other similar conditionals, I believe the change in v-model
is triggering a re-render.我看到输入有
v-model="cell.data.data.width.width"
和父有v-if="cell.data.data.width.set"
而这不应该引起问题,它可能可能还有其他类似的条件,我相信v-model
的变化正在触发重新渲染。 If that is the case, I think you may be able to resolve it by adding a key to the input.如果是这种情况,我认为您可以通过在输入中添加一个键来解决它。 Something that doesn't change, ideally something like
cell.data.data.width.id
不会改变的东西,最好是像
cell.data.data.width.id
Give the input a key给输入一个键
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.