Home > Web Front-end > Vue.js > body text

What is the use of vuejs el?

青灯夜游
Release: 2021-09-18 17:58:43
Original
3233 people have browsed it

In vuejs, the function of el is to specify the mounting target of the Vue instance, and will provide a DOM element that already exists on the page as the mounting target of the Vue instance; after the instance is mounted, the element can Use "vm.$el" to access.

What is the use of vuejs el?

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

In the vue official API document, el has the following description:

https://cn.vuejs.org/v2/api/#el

# Everyone knows the role of

##el, which is used to specify the mounting target of the Vue instance. We focus on the two red exclamation mark parts above. To summarize:

If there is a render function or template attribute, the mounted element will be replaced by the DOM generated by Vue; otherwise, the HTML where the mounted element is located will be extracted and used Make a template

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title></title>
  </head>
  <body>
    <div id="ppp"></div>
  </body>
</html>
Copy after login

Example 1: Replace the DOM rendered by the render function

new Vue({
  el: &#39;#ppp&#39;,
  router,
  store, 
  render: h => h(App)
})
Copy after login

Example 2: String template replacement

new Vue({
  el: &#39;#ppp&#39;,
  router,
  components: { App },
  template: &#39;<App/>&#39;
})
Copy after login

Example 3: Manual mounting and render does not exist Functions and template attributes

new Vue({
  router,
  store,
}).$mount(&#39;#ppp&#39;)
Copy after login

Related recommendations: "

vue.js Tutorial"

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template