<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>全局组件与局部组件</title>
<script src="../js/vue.js"></script>
</head>
<body>
<template id="t1">
<h3>举头望明月</h3>
</template>
<template>
<h3>低头思故乡</h3>
</template>
<div id="demo">
<all-component></all-component>
<div id="demo2">
<mini-com></mini-com>
</div>
<div id="demo3">
<cpt></cpt>
</div>
</div>
<script>
// 组件不能单独使用,需要嵌套在块级标签内
// template内置创建全局组件
Vue.component(
"all-component",{
template: `
<h3>窗前明月光</h3>
`
}
),
// template外置创建全局组件
Vue.component(
"cpt", {
template: "#t1"
}
)
new Vue({
el:"#demo"
})
new Vue({
el:"#demo3"
})
// 创建局部组件
new Vue({
el: "#demo2",
components: {
"mini-com": {
template: `
<h3>It's 地上霜</h3>
`
}
}
})
</script>
</body>
</html>