I've been working on creating a Component for titles that are editable when double-clicked. The Component takes the specific h-tag and title as props, generating a regular h-tag that transforms into an input field upon double click. It's functioning properly with single instances on a page, but encounters issues when multiple Components are utilized due to improper scoping. I'm currently stuck on how to resolve this issue, here is the code snippet:
<template>
<div class="edit-on-click">
<input
:class="sizeClass"
type="text"
v-if="edit"
v-model="editedTitle"
@blur="finishEdit"
@keyup.enter="finishEdit"
v-focus="true"
/>
<span v-show="!edit" @dblclick.prevent="edit = true"></span>
</div>
</template>
Struggling with scoping in the mounted hook:
mounted() {
let node = document.createElement(this.size); // Accepts h-tag (h1, h2 etc.)
let titleText = document.createTextNode(this.finalTitle); // Accepts title
node.appendChild(titleText);
node.classList.add("editable-title");
// This causes issues with multiple components on the page
document.getElementsByTagName("span")[0].appendChild(node);
},
Any suggestions on how to efficiently scope this? Thanks in advance!