<template>
<div ref="sendContent" contenteditable="true" v-html="sendContent" @keyup.shift.enter="sendMsg" style="min-height:50px;border:1px solid black;"></div>
<button @click="clearTextarea">清空输入框的值</button>
</template>
<script>
export default {
data () {
return {
sendContent: ''
}
},
methods: {
sendMsg () {
let content = this.$refs.sendContent.innerHTML
if ((content.length) > 1200) {
alter('您输入的内容过长,无法发送')
return false
}
this.$emit('send', this.sendContent)
},
clearTextarea: function(){
//无效 this.sendContent = '';
this.$refs.sendContent.innerHTML = '';
}
}
}
</script>
参考文章: