vue中el是什么?
分类:vue
vue官方API文档
对el描述:https://cn.vuejs.org/v2/api/#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)
})

示例2:字符串模版替换 <div id=”myapp”></div>
new Vue({
el: '#myapp',
router,
components: { App },
template: '<App/>'
})

示例3:手动挂载且不存在render函数和template属性
new Vue({
router,
store,
}).$mount('#myapp')

一线大厂高级前端编写,前端初中阶面试题,帮助初学者应聘,需要联系微信:javadudu