In-depth study of vue2.x--Explanation of the h function

In-depth study of vue2.x--Explanation of the h function

vue project. The code written in the template of the .vue file needs to be parsed with the help of the webpack template parser plug-in. When a single .html file introduces a vue file, the vue file also introduces the template parser (the disadvantage is that it is large in size).

Therefore, when we use engineering development projects, we need to introduce vue-template-compile in the package.json file for template parsing.

insert image description here

If there is no template parser, it cannot be parsed, but vue-template-compile can only parse templates in .vue files, and cannot parse templates in .js files:

So when we write this, it won't work.

insert image description here

insert image description here

Why can't it be parsed? Because the vue file introduced by the main.js file does not have a template parser

insert image description here

insert image description here

vue.runtime.common.js is a .vue file without a template parser, and vue.js is a vue file with a template parser

insert image description here

If we import the vue.js file with the template parser in main.js, we can parse the template

insert image description here

insert image description here

Why is the vue.js file without template parser imported by default?
Because of the volume issue:

insert image description here

Solution,

Use the official render function. He can call the introduced vue-template-compile through the h function, that is, the ninth line of code is equivalent to the eleventh and twelfth lines plus the loader template parser.

insert image description here

Summarize:

insert image description here

This article ends here. I hope it can be helpful to you. I also hope that you can pay more attention to more content on 123WORDPRESS.COM!

You may also be interested in:
  • Detailed explanation of how to use $props, $attrs and $listeners in Vue

<<:  Implementation of remote Linux development using vscode

>>:  MySQL derived table (Derived Table) simple usage example analysis

Recommend

JavaScript counts the number of times a character appears

This article example shares the specific code of ...

Vue implements pull-down to load more

Developers familiar with Element-UI may have had ...

How to use cutecom for serial communication in Ubuntu virtual machine

Using cutecom for serial communication in Ubuntu ...

Detailed explanation of Vue components

<body> <div id="root"> <...

Navicat for MySQL scheduled database backup and data recovery details

Database modification or deletion operations may ...

Detailed example of Linux all-round system monitoring tool dstat

All-round system monitoring tool dstat dstat is a...

Detailed explanation of how to restore database data through MySQL binary log

Website administrators often accidentally delete ...

Comparison of various ways to measure the performance of JavaScript functions

Table of contents Overview Performance.now Consol...

Detailed explanation of the use of Join in Mysql

In the previous chapters, we have learned how to ...

Is it necessary to give alt attribute to img image tag?

Do you add an alt attribute to the img image tag? ...

mysql 5.7.20 win64 installation and configuration method

mysql-5.7.20-winx64.zipInstallation package witho...

The image element img has extra blank space in IE6

When doing DIV+CSS layout of the page, it is very...

Detailed explanation of JS browser storage

Table of contents introduction Cookie What are Co...

innodb_flush_method value method (example explanation)

Several typical values ​​of innodb_flush_method f...

Web Design: Web Music Implementation Techniques

<br />When inserting music into a web page, ...