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>
Also in JavaScript:
- how to prevent previous radio button active react native
- require("history").createBrowserHistory` instead of `require("history/createBrowserHistory")`
- random item from array javascript
- jquery confirmation dialog example
- routes in node js
- testing library react hooks
- get number of creeps screeps
- create and append element in javascript
- paper material ui improt
- openssl error Subject does not start with '/'
- js jquery class ending with string
- d3js circle out of scrren
- js create object url base64 pdf binary
- reduce method in javascript array of bjects
- JQuery UI Saving Sortable List
- file origin does not match viewer's pdf.js
- mlutiple css jquery
- how to javascript
- javascript get div x y position
- user agents regex for mobile
- sort data according to date in js
- javascript loop through arrya
- javascript tostring
- create react native app npx