<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=adge">
<title>Document</title>
<script src="vue.js"></script>
</head>
<body>
<div id="app">
<mycom3></mycom3>
<mycom4></mycom4>
</div>
<div id="app2">
<mycom3></mycom3>
<!-- 由于下面的UI结构是私有的,所以不会调用显示 -->
<mycom4></mycom4>
</div>
<!-- 定义一个template标签元素 -->
<!-- 使用Vue提供的template标签,可以定义组件的UI模板结构 -->
<template id="tmpl">
<div>
<h1>我在外面定义的组件UI模板结构</h1>
<h1>我的外面必须要有唯一一个根元素存在</h1>
</div>
</template>
</body>
<script>
Vue.component("mycom3",{
template:"#tmpl"
})
//创建Vue实例,得到ViewModel
var vm=new Vue({
el:"#app",
data:{},
methods:{},
components:{//定义实例中的私有组件,组件的名称,和组件的结构
"mycom4":{
template:"<h4>我是私有组件里的</h4>"
}
}
});
var vm=new Vue({
el:"#app2",
data:{},
methods:{}
});
</script>
</html>