Home  >  Article  >  Web Front-end  >  What is vue template precompilation?

What is vue template precompilation?

青灯夜游
青灯夜游Original
2022-12-20 18:31:402442browse

When vue is packaged, it will directly convert the template in the component into a render function. This is called template pre-compilation. The benefits of template pre-compilation: templates no longer need to be compiled at runtime, which improves running efficiency; and the Vue compiled code is no longer needed in the packaging results, reducing the packaging volume.

What is vue template precompilation?

The operating environment of this tutorial: windows7 system, vue3 version, DELL G3 computer.

Template pre-compilation

#When using templates within the DOM or string templates within JavaScript, the template will be compiled for rendering at runtime function. Usually this process is fast enough, but performance-sensitive applications are best to avoid this usage.

The easiest way to precompile a template is to use a single file component - the relevant build settings will automatically handle the precompilation, so the built code already contains the compiled rendering function instead of the original template String.

If you use webpack and like to separate JavaScript and template files, you can use vue-template-loader, which can also convert template files into JavaScript rendering functions during the build process.

Simply put, when vue is packaged, it will directly convert the template in the component into a render function. This is called template pre-compilation.

The advantage of doing this is:

It is no longer necessary to compile the template during runtime, which improves the running efficiency. The vue compiled code is no longer required in the packaging result, reducing the packaging volume

What is vue template precompilation?

[Related recommendations: vuejs video tutorial, web front-end development

The above is the detailed content of What is vue template precompilation?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:what is vue vwNext article:what is vue vw