I have a Vue view where the search input automatically focuses when opened. However, if the user clicks away from the input, I want the view to redirect back.
I've searched for solutions to this problem but have not had any luck. Here is my code using Vue JS 2:
<input v-focus="focused" @focus="focused = true" @blur="focused = false" type="text" class="form-control" aria-label="search">
import { focus } from 'vue-focus'
export default {
directives: { focus: focus },
data () {
return {
focused: true
}
}
}
I am currently using the vue-focus package, but I'm open to suggestions for native solutions.
If the input loses focus, I would like it to automatically redirect to another link.