|
@@ -1,24 +1,40 @@
|
|
|
<template>
|
|
<template>
|
|
|
<section>
|
|
<section>
|
|
|
- <div contenteditable @input.stop="changeValue">
|
|
|
|
|
- {{ content }}
|
|
|
|
|
- </div>
|
|
|
|
|
- {{ content }}
|
|
|
|
|
|
|
+ <div
|
|
|
|
|
+ contenteditable
|
|
|
|
|
+ @keydown.stop="handleKeyDown"
|
|
|
|
|
+ :v-html="innerContent"
|
|
|
|
|
+ ></div>
|
|
|
|
|
+ 输入的内容为:{{ innerContent }}
|
|
|
</section>
|
|
</section>
|
|
|
</template>
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
<script>
|
|
|
|
|
+import { CREATE_ITEM_AFTER } from '../store/types/editor-types'
|
|
|
export default {
|
|
export default {
|
|
|
name: 'editable-item',
|
|
name: 'editable-item',
|
|
|
- props: ['tagName', 'content'],
|
|
|
|
|
- data: () => {
|
|
|
|
|
|
|
+ props: ['id', 'tagName', 'content'],
|
|
|
|
|
+ data: function() {
|
|
|
return {
|
|
return {
|
|
|
- content: '123'
|
|
|
|
|
|
|
+ innerContent: this.content
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
methods: {
|
|
methods: {
|
|
|
- changeValue: function(e) {
|
|
|
|
|
- this.content = e.target.innerText
|
|
|
|
|
|
|
+ handleKeyDown(e) {
|
|
|
|
|
+ console.log(e.key)
|
|
|
|
|
+
|
|
|
|
|
+ switch (e.key) {
|
|
|
|
|
+ case 'Enter':
|
|
|
|
|
+ e.preventDefault()
|
|
|
|
|
+ this.$store.commit(CREATE_ITEM_AFTER, { id: this.id })
|
|
|
|
|
+ break
|
|
|
|
|
+
|
|
|
|
|
+ default:
|
|
|
|
|
+ requestAnimationFrame(() => {
|
|
|
|
|
+ this.innerContent = e.target.innerText
|
|
|
|
|
+ })
|
|
|
|
|
+ break
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|