如何以编程方式聚焦v- radio -group选定的电台?
<v-radio-group v-model="radios" :mandatory="false" ref="RadioGroup">
<v-radio label="Radio 1" value="radio-1"></v-radio>
<v-radio label="Radio 2" value="radio-2"></v-radio>
</v-radio-group>
我尝试使用this.$refs.RadioGroup.focus()
,但什么也没有发生。提前谢谢你
发布于 2018-12-11 08:23:53
两件事
这是可行的,所以可能会给你一个可以使用的想法。
<v-radio-group v-model="radios" :mandatory="false" ref="RadioGroup">
<v-radio label="Radio 1" value="radio-1" ref="Radio1"></v-radio>
<v-radio label="Radio 2" value="radio-2" ref="Radio2"></v-radio>
</v-radio-group>
this.$refs.Radio2[0].$el.children[0].children[0].focus()
使用此监听器进行了测试
created() {
document.addEventListener('focusin', event => {
console.log('focused', event.target)
})
},
发布于 2018-12-16 04:24:04
尝试使用custom directive。将'radio- focus‘作为指令添加到Vue实例中,将v-radio-focus指令作为属性添加到您希望关注的v-radio元素中。有关指令here的更多信息。
'radio-focus': {
// directive definition
inserted: function (el) {
const $el: HTMLElement = el.children[0].children[0] as HTMLElement
$el.focus()
}
}
https://stackoverflow.com/questions/53714208
复制相似问题