Skip to content

Instantly share code, notes, and snippets.

@ctf0
Last active August 13, 2021 21:48
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ctf0/2789d97b8301bcc6219b30734d224033 to your computer and use it in GitHub Desktop.
Save ctf0/2789d97b8301bcc6219b30734d224033 to your computer and use it in GitHub Desktop.
  • we dont use @input to save changes as it will reset the cursor, so we use @blur instead
<td contenteditable dir="auto"
    v-html="someText"
    @keydown.enter.prevent
    @input="newEntry()"
    @blur="saveNewValue($event)">
</td>

<script>
export default{
    data() {
        return {
            someText: 'abc',
            dataChanged: false
        }
    },
    methods: {
        newEntry() {
            this.dataChanged = true // maybe to enable the submit btn
        },
        saveNewValue(e) {
            // e.target.innerHTML
        },
    }
}

</script>
@JakubKoralewski
Copy link

Very helpful!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment