属性
new Vue({
//绑定元素
el:'#app',
//要绑定的数据
data:{},
//用来接受外部资料的属性
props:{},
// 用来定义在Vue内使用的方法
methods:{},
//用来观察Vue 数据的更新
watch:{},
//自动为内部数据计算的属性
computed:{},
// 提供Vue 实体编译后的样板
template:{},
//用来定义子元件
components:{}
});
大多数的数据都相同,唯一要注意的就是data属性
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/4.2.0/normalize.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.3.4/vue.js"></script>
<style>
#app{
margin: 1em;
font-size: 1.2em;
}
.component{
border: 1px solid #000;
padding: 10px;
}
</style>
</head>
<body>
<div id="app">
{{msg}}
<hr>
<my-component></my-component>
</div>
<script>
//register
Vue.component('my-component',{
template:' <div class="component">{{msg}}</div>',
data:function () {
return{
msg:'A custom component of Vue!'
}
}
});
//create wa root instance
new Vue({
el:'#app',
data:{
msg:'A root msg of Vue!'
}
});
</script>
</body>
</html>