Skip to content Skip to sidebar Skip to footer

Vue Component/element Creating While Method Is Working

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

Solution 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)

Post a Comment for "Vue Component/element Creating While Method Is Working"