vue中el是什么?

我心飞翔 分类:vue

vue官方API文档

对el描述https://cn.vuejs.org/v2/api/#el

vue中el是什么?

el 的作用大家都知道,用于指明 Vue 实例的挂载目标。我们重点关注上面两个红色叹号部分,总结一下就是:如果存在 render 函数或 template 属性,则挂载元素会被 Vue 生成的 DOM 替换;否则,挂载元素所在的 HTML 会被提取出来用作模版

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title></title>
  </head>
  <body>
    <div id="myapp"></div>
  </body>
</html>

示例1: render 函数渲染的 DOM 替换 <div id=”myapp”></div>

new Vue({
  el: '#myapp',
  router,
  store, 
  render: h => h(App)
})

vue中el是什么?

示例2:字符串模版替换 <div id=”myapp”></div>

new Vue({
  el: '#myapp',
  router,
  components: { App },
  template: '<App/>'
})
vue中el是什么?

示例3:手动挂载且不存在render函数和template属性

new Vue({
  router,
  store,
}).$mount('#myapp')
vue中el是什么?

回复

我来回复
  • 暂无回复内容