mirror of
https://github.com/anatolykopyl/vue-highlights.git
synced 2026-03-26 12:55:35 +00:00
Fixed two way binding
This commit is contained in:
18
src/index.js
18
src/index.js
@@ -27,16 +27,21 @@ export default {
|
|||||||
},
|
},
|
||||||
data () {
|
data () {
|
||||||
return {
|
return {
|
||||||
focused: false,
|
focused: false
|
||||||
body: ''
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
|
valueModel: {
|
||||||
|
get () { return this.value },
|
||||||
|
set (value) {
|
||||||
|
this.$emit('input', value)
|
||||||
|
}
|
||||||
|
},
|
||||||
showPlaceholder () {
|
showPlaceholder () {
|
||||||
return !this.body.replace(/^\s*\n/gm, '').length
|
return !this.valueModel.replace(/^\s*\n/gm, '').length
|
||||||
},
|
},
|
||||||
computedBody () {
|
computedBody () {
|
||||||
return highlight(this.body, {
|
return highlight(this.valueModel, {
|
||||||
extractUrlsWithoutProtocol: this.extractUrlsWithoutProtocol
|
extractUrlsWithoutProtocol: this.extractUrlsWithoutProtocol
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -64,15 +69,14 @@ export default {
|
|||||||
},
|
},
|
||||||
clear () {
|
clear () {
|
||||||
this.$refs.mbody.innerText = ''
|
this.$refs.mbody.innerText = ''
|
||||||
this.body = ''
|
this.valueModel = ''
|
||||||
},
|
},
|
||||||
onKeyUp (e) {
|
onKeyUp (e) {
|
||||||
let caretPosition = this.getCaretPos()
|
let caretPosition = this.getCaretPos()
|
||||||
if (e.keyCode === 13) { // Enter key
|
if (e.keyCode === 13) { // Enter key
|
||||||
caretPosition++
|
caretPosition++
|
||||||
}
|
}
|
||||||
this.body = e.target.innerText
|
this.valueModel = e.target.innerText
|
||||||
this.$emit('input', this.body)
|
|
||||||
this.$nextTick(() => {
|
this.$nextTick(() => {
|
||||||
this.setCaretPos(caretPosition)
|
this.setCaretPos(caretPosition)
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user