Vue component/element creating while method is working

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-20 09:02:09

问题


I have a parser method inside my component, when that method is working I want to create components (or even just elements) from values that is computed. Is it possible to creating component or html elements when method is working?


回答1:


Is it possible to creating component or html elements when method is working?

Its not possible in JavaScript using synchronous code. JavaScript is single-threaded and even browser rendering is blocked when your synchronous/long running code is executing, not to mention Vue logic which re-renders your template and updates the DOM (really recommend this talk - explains the problem beautifully)

You have basically two options:

  1. Split up you workload into smaller chunks, process only one at a time and use setTimeout(nextBatch, 0) to schedule "next chunk" processing. See this SO question for more details...
  2. You can offload your computation to WebWorker which is running in its own thread but brings new challenges (for example data between your Vue app and Web Worker need to be serialized/deserialized on both sides)


来源:https://stackoverflow.com/questions/59092698/vue-component-element-creating-while-method-is-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!