<title>Document</title>
<script src="/lib/vue.js"></script>
</head>
<body>
<div id="box">
<xby></xby>
<xby></xby>
<xby3></xby3>
</div>
<script>
// 定义一个全局的组件
Vue.component("xby",{
// dom,js,css
template:`<div style="background:red ">
<button @click="handleLeft">left</button>
猫眼电影-{{myname}}
<button @click="handleRight">right</button>
<xby2></xby2>
</div>`,
methods:{
handleLeft(){
console.log("left")
},
handleRight(){
console.log("right")
}
},
computed:{},
watch:{},
// data必须是函数写法
data(){
return {
myname:"111112"
}
},
// 局部的,只能在当前父之下使用
components:{
"xby2":{
template:`
<div>chiid</div>
`
}
}
})
// 全局的,可以在任何地方使用
Vue.component("xby3",{
template:`
<div style="background:yellow">公司标签</div>`
})
// 根组件
new Vue({
el:"#box"
})
</script>
</body>
局部的只能在定义的父中使用,全局的可以在任何一个地方使用。