【发布时间】:2018-08-14 01:15:32
【问题描述】:
我想为我的组件使用 HTML 的 contenteditable 属性来使区域可编辑。
为此,我使用了@input 指令,但它并没有像我预期的那样工作。 我希望插入符号保持整个输入值的末尾,但它会移动到头部位置。
动画 Gif 图片
演示
https://codesandbox.io/s/oj9p82kvp6
代码
<template>
<div>
<p contenteditable="true" @input="update">{{ text }}</p>
</div>
</template>
<script>
export default {
name: 'ReadWrite',
data () {
return {
text: 'edit here!'
}
},
methods: {
update (e) {
this.text = e.target.textContent
}
}
}
</script>
<style scoped>
:read-write {
border: solid 1px #cccccc;
padding: 5px;
}
</style>
【问题讨论】: