Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

content editable vuejs

<template>
  <div>
    <p
      v-for="(value, index) in content"
      :id="`content-${index}`"
      :key="index"
      contenteditable
      @input="event => onInput(event, index)"
      @keyup.delete="onRemove(index)"
    />
  </div>
</template>

<script>
export default {
  data() {
    return {
      content: [
        { value: 'paragraph 1' },
        { value: 'paragraph 2' },
        { value: 'paragraph 3' },
      ],
    };
  },
  mounted() {
    this.updateAllContent();
  },
  methods: {
    onInput(event, index) {
      const value = event.target.innerText;
      this.content[index].value = value;
    },
    onRemove(index) {
      if (this.content.length > 1 && this.content[index].value.length === 0) {
        this.$delete(this.content, index);
        this.updateAllContent();
      }
    },
    updateAllContent() {
      this.content.forEach((c, index) => {
        const el = document.getElementById(`content-${index}`);
        el.innerText = c.value;
      });
    },
  },
};
</script>
Comment

PREVIOUS NEXT
Code Example
Javascript :: how to set current date and time in jquery datetime-local 
Javascript :: discord js fetch user 
Javascript :: livewire upload progress 
Javascript :: json rename key 
Javascript :: merge data to json js 
Javascript :: dom click is not a function 
Javascript :: destructure dynamic properties 
Javascript :: query selector has clas 
Javascript :: find the max length of string elements in an array 
Javascript :: buffer from base64 
Javascript :: rounding off numbers javascript 
Javascript :: javascript current date time 
Javascript :: add multiple class list at once in js 
Javascript :: javascript check if object property exists 
Javascript :: slicknav cdn 
Javascript :: javascript parse json string 
Javascript :: javascript dice throw 
Javascript :: hardhat test 
Javascript :: js append en tête 
Javascript :: auto closing parenthese not working on vscode 
Javascript :: maximum sum subarray javascript 
Javascript :: encodeuricomponent js 
Javascript :: javascript remove duplicated from Array 
Javascript :: javascript undefined check 
Javascript :: react scroll reset in component 
Javascript :: javascript to string big number 
Javascript :: daysinmonth javascript 
Javascript :: window.scroll 
Javascript :: confetti for javascript 
Javascript :: local storal javascript 
ADD CONTENT
Topic
Content
Source link
Name
8+9 =