Vue中el的理解
Vue中的el,称之为挂载点,它有两种写法
1.new Vue({ el: '#app' });
2.new Vue({ }).$mount('#app');
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/html">
<head>
<meta charset="UTF-8">
<title>数据绑定</title>
</head>
<body>
<!--
<div id="app">
1.{{message}}
</div>
<hr/>
<h1 id="app",class="app">
2.{{message}}
</h1>
<hr/>
<span>3.{{message}}</span>
-->
<!--<span></span>没有与Vue绑定,不会显示出'你好!'-->
</body>
</html>
<script src="../js/vue.js"></script>
<script>
new Vue({
// el: '#app',//对应的id选择器
//el:'.app',//对于的class选择器
date:{
message:'你好!'
}
});
/*
new Vue({
}).$mount('#app');*/
</script>
- Vue会管理与Vue进行el绑定的元素及其内部的后代元素,建议使用id选择器,可以使用其他的双标签,不能使用html和body。
- el绑定的元素内,都是Vue的作用范围。
- 一个Vue实例只能绑定一个el。