Может быть, что-то вроде этого:
export default {
watch: {
someVarFromVuex(value) {
// Don't focus unless the value got switched on
if (!value) return;
// Make sure to add the ref to your template.
// You could also use an id.
const $input = this.$refs.input.$el;
// Just in case the input somehow doesn't exist...
if ($input) {
this.$nextTick(() => {
$input.focus();
})
}
},
},
};
Обратите внимание, что если вы на самом деле пытаетесь сфокусировать div
, тогда ему нужно будет иметь tabindex
.