M
M
mixejuxix2019-09-16 18:48:15
Vue.js
mixejuxix, 2019-09-16 18:48:15

How to bind div to data?

There are . I want to bind it to data. If I do it reactively (remove v-once) I get cursor issues when printing - vue updates the div and puts the cursor at the beginning. If I put v-once, then I can’t push data into div.<div contenteditable >
<div contenteditable v-once v-html="data" />

props: ['value'],
beforeMount() {
    //Тут this.value еще undefined
    this.$nextTick(function () {
        this.data = this.value //Тут div уже отрендерен, v-once отработал, не обновляется
    }.bind(this))
},

You need to either push the data from the prop value before the v-once fires, or somehow solve the problem with the cursor.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Belyaev, 2019-09-16
@mixejuxix

<div contenteditable ref="dataElem" />

props: ['value'],
mount() {
    this.$nextTick(() => {
        this.$refs.dataElem.innerHTML = this.value;
    });
},

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question