关于vue.js:为什么我的所见即所得编辑器在vuejs中工作如此缓慢?

why my wysiwyg editor works so slow in vuejs?

我决定在页面上使用所见即所得编辑器。我正在通过v-model="text"和simpy输出使用简单的双向数据绑定。我是vuejs的初学者,但我需要问以下问题:
为什么运行这么慢?不管是quill editor/medium-editor/vueditor

每次我输入新字母时,延迟都非常明显,用户体验也很差。我的控制台显示一条消息:

1
[Violation] 'message' handler took 199ms

有时

1
2
[Violation] Added synchronous DOM mutation listener to a 'DOMNodeInserted'
event. Consider using MutationObserver to make the page more responsive.

如果我将其绑定到计算属性(延迟最多250ms),那就更糟了,我将需要尽快执行此操作。在我的情况下,我还需要进行双向数据绑定。

我在做什么错?如何加快打字过程并改善打字体验?我的组件大约有1,5k行。可能是这样吗?

编辑:

我已将我的1,5k行代码部分分解为单独的部分进行编辑,这已经将Web速度从大约250毫秒提高到了50-60毫秒,但是所见即所得的编辑器和双向数据绑定仍然很慢。

edit2:代码(使用vuetify)

Example1(中速):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<v-text-field
  label="Write something"
  v-model="text"
  counter
  max="120"
  rows="3"
  full-width
  multi-line
  single-line
></v-text-field>


data () {
  return {
    text: ''
  }
},
computed: {
  textComputed() {
  //using computed to add
<li>
 tags
    return '
<li>
' + this.text.replace(/\
/g,"<br />
</li>

<li>
") + '
</li>
'
  }
}

Example2(慢):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<quill-editor
      v-model="text"
      :options="editorOptionProTemplate"
      >
</quill-editor>


data () {
  return {
    text: ''
  }
},
computed: {
  //using computed for many variants for styling output in web (here just adding  tag)
  textComputed() {
    return '' + this.text + ''
  }
}


我认为您最好的朋友在弹跳。您可以v建模其set函数对值的设置进行反跳的计算对象:

1
2
3
4
5
6
debounceText: {
  get() { return this.text; },
  set: _.debounce(function(newValue) {
    this.text = newValue;
  }, 100)
},

您将在更新HTML输出中看到一些滞后,但是在键入时在编辑器中的滞后减少了。我做了一个小提琴来演示。在其中复制一堆文本,看看它如何为您处理。