【发布时间】:2018-04-11 04:37:47
【问题描述】:
我注册了一个用于聚焦输入的自定义指令。我使用来自Vue docs的代码:
// Register a global custom directive called v-focus
Vue.directive('focus', {
// When the bound element is inserted into the DOM...
inserted: function (el) {
// Focus the element
el.focus()
}
})
我在这些元素上应用v-focus:
<input v-show="isInputActive" v-focus>
<div v-show="isDivActive">
<input v-focus>
</div>
但它不起作用。只有当我用v-if 替换v-show 时它才有效,但我必须使用v-show。有解决办法吗?
【问题讨论】:
-
每次
v-show指令中的条件被赋值为true时,您的元素都不会重新渲染。有关更多信息,请参阅此处的文档:vuejs.org/v2/guide/conditional.html#v-if-vs-v-show -
我知道,事实上我在问如何使用 v-focus 和 v-show
-
它是否适用于
v-if?然后它应该重新渲染... -
用 v-if 可以,但我需要使用 v-show
标签: javascript vue.js vuejs2