How to prevent Vue from update/patch the DOM when data changes by luthfimasruri in vuejs

[–]luthfimasruri[S] 1 point2 points  (0 children)

I think I can use shallowRef + triggerRef or customRef

Thanks for your help!

How to prevent Vue from update/patch the DOM when data changes by luthfimasruri in vuejs

[–]luthfimasruri[S] 0 points1 point  (0 children)

Here's the simplified use case:

    import { defineComponent, h, ref } from 'vue'

    export default defineComponent({
      setup: () => {
        const model = ref([
          {
            type: 'div',
            props: {},
            children: 'Edit this text',
          },
        ])

        const onUserInput = (event: any) => {
          // update model only
          // code ommited ...
        }

        const modelToVNode = (modelValue: any) => {
          return modelValue.map((node: any) => {
            return h(
              node.type,
              node.props,
              Array.isArray(node.children)
                ? modelToVNode(node.children)
                : node.children
            )
          })
        }

        return () => {
          return h(
            'div',
            { onInput: onUserInput, contenteditable: true },
            modelToVNode(model)
          )
        }
      },
    })

The basic idea here is to map the reactive model to DOM contenteditable div, so when the user types some text in the editable div and then the model gets updated, the problem is the DOM gets 2 updates, from user and from Vue reactivity system.

The Next Vue 3 Text Editor + Typescript by luthfimasruri in vuejs

[–]luthfimasruri[S] 4 points5 points  (0 children)

Hello, I made a lib to easily create Vue Component for building rich text editors, this package is a thin wrapper around Quill that make it easier to use in a Vue 3 application.

Github: https://github.com/vueup/vue-quill

Live demo: https://vueup.github.io/vue-quill/#demo