简体   繁体   English

Vue.js 中的“挂载”是什么意思?

[英]What does "mount" mean in Vue.js?

What does "mount" mean on using instance of vue.js to target a DOM element?使用 vue.js 的实例来定位 DOM 元素时,“mount”是什么意思? (even in plain English?). (即使是简单的英语?)。 For example in following:例如在以下:

This code creates a new instance of Vue and mounts it on the HTML element with the ID of app.这段代码创建了一个新的 Vue 实例,并将其安装在 ID 为 app 的 HTML 元素上。

 const app = new Vue().$mount('#app');

When the Vue instance has the el option, it automatically mounts to that element当 Vue 实例有 el 选项时,它会自动挂载到该元素

Mounting takes place at the Virtual Dom Level, before the User sees anything.在用户看到任何东西之前,挂载发生在 Virtual Dom 级别。

When you $mount('#app'), there will be an 'el' parameter that gets set.当您 $mount('#app') 时,将设置一个 'el' 参数。 This 'el' defines the ID of the element that this instance will be "mounted" to.这个 'el' 定义了这个实例将被“挂载”到的元素的 ID。

So, in your template, if you have an element that you want to be the mounted component, then in your declaration of the component, you would mount it with "el: #app".因此,在您的模板中,如果您有一个想要成为已安装组件的元素,那么在您的组件声明中,您将使用“el:#app”安装它。

VueJS Life-Cycle Diagram: https://v2.vuejs.org/v2/guide/instance.html#Lifecycle-Diagram VueJS 生命周期图: https ://v2.vuejs.org/v2/guide/instance.html#Lifecycle-Diagram

Mounted Life-Cycle Hook: https://v2.vuejs.org/v2/api/#mounted挂载的生命周期钩子: https ://v2.vuejs.org/v2/api/#mounted

What is mounting in vue? vue 中的挂载是什么? In vue, every instance is first stored as Virtual DOM objects(virtual html elements) in memory.When Vue create those components(virtual DOM)visible to the real DOM(Actual html elements) , the moment in which it create virtual DOM into real DOM is call 'Mounting'.在 vue 中,每个实例首先作为虚拟 DOM 对象(虚拟 html 元素)存储在内存中。当 Vue 创建那些对真实 DOM 可见的组件(虚拟 DOM)时(实际 html 元素),它创建虚拟 DOM 的那一刻变成了真实的DOM 被称为“安装”。 As the app state changes , vue detect changes user expect to see and put data changes to the real DOM from the memory.That is called an 'update'.随着应用程序状态的变化,vue 会检测用户期望看到的变化,并将数据变化从内存中放入真实的 DOM。这称为“更新”。 The entire process is called Vue Lifescyclehooks which has four stages, namely create , mount , update and destroyed .整个过程称为 Vue Lifescyclehooks,它有四个阶段,即createmountupdatedestroyed

“mount”表示将Component插入DOM的时刻。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM