Answer the question
In order to leave comments, you need to log in
How to catch focus on an element using vuejs?
Hello, I have this code:
<template>
<span
tabindex="-1"
contenteditable="true"
spellcheck="false"
style="width: 800px"
v-text="displayText.join('')"
@focus="focused = true"
/>
</template>
Answer the question
In order to leave comments, you need to log in
Sorry, I'm writing from a mobile phone, if it's still relevant and based on the comments above.
mplate>
<div id="app">
<span
contenteditable="true"
spellcheck="false"
style="width: 800px; display: block"
v-text="textEl"
@focus="focused = true"
@blur="focused = false"
/>
{{ focused }}
</div>
</template>
<script>
export default {
data() {
return {
focused: false,
};
},
computed: {
textEl() {
if (this.focused) {
return "text with focus";
} else {
return "text with not focus";
}
},
},
};
</script>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question