Home >Web Front-end >Vue.js >What is the use of vuejs el?

What is the use of vuejs el?

青灯夜游
青灯夜游Original
2021-09-18 17:58:433308browse

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>

Example 1: Replace the DOM rendered by the render function0b56aebb5df5b06b70a352c6e82d051d94b3e26ee717c64999d7867364b1b4a3

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

Example 2: String template replacement0b56aebb5df5b06b70a352c6e82d051d94b3e26ee717c64999d7867364b1b4a3

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

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

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

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!

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